-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy path_1110.java
More file actions
65 lines (52 loc) ยท 1.36 KB
/
_1110.java
File metadata and controls
65 lines (52 loc) ยท 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package backjoon;
// https://www.acmicpc.net/problem/1110
// ๋ํ๊ธฐ ์ฌ์ดํด
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
public class _1110 {
public static void main(String[] args) throws Exception {
//sol1. memory 11500 runtime 84
/*
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int tens = 0; //์ญ์ ์๋ฆฌ์ ์
int units = 0; //์ผ์ ์๋ฆฌ์ ์
int sum = n;
int cnt = 0;
while(true){
tens = sum/10;
units = sum%10;
sum = tens + units;
sum = units*10 + sum%10;
cnt++;
if(n == sum){
break;
}
}
*/
//sol2. memory 18356 runtime 228
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
// ์
๋ ฅ ์๊ฐ 10๋ฏธ๋ง์ด๋ฉด n์ 10์ ๊ณฑํจ
if (n < 10)
n *= 10;
int ์ฒซ์งธ์๋ฆฌ์ = 0;
int ๋์งธ์๋ฆฌ์ = 0;
int cnt = 0;
int sum = n;
while (true) {
์ฒซ์งธ์๋ฆฌ์ = sum / 10;
๋์งธ์๋ฆฌ์ = sum % 10;
sum = ์ฒซ์งธ์๋ฆฌ์ + ๋์งธ์๋ฆฌ์;
sum = ๋์งธ์๋ฆฌ์ * 10 + sum % 10; // 10์ด์์ ์๊ฐ ๋์์๋ ๋ง์ง๋ง ์๋ฆฌ ์๋ก ํด์ผํ๊ธฐ ๋๋ฌธ
cnt++;
if (sum == n)
break;
}
System.out.println(cnt);
}
}
/*
input 26 output 4
*/