μκ³ λ¦¬μ¦ λ¬Έμ νμ΄
[λ°±μ€]Q1110 λνκΈ° μ¬μ΄ν΄(μλ°)
JihyunLee
2019. 9. 29. 12:55
λ°μν
λ°±μ€ 1110 λ² λνκΈ° μ¬μ΄ν΄ λ¬Έμ λ₯Ό μλ°λ₯Ό μ΄μ©ν΄μ νμλ€.
λ±ν μλ£κ΅¬μ‘°κ°μκ²μ΄ νμνμ§ μμλ€.
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
|
import java.util.*;
public class Q1110{
public static void main(String[] args){
Scanner scan = new Scanner(System.in);
int N = scan.nextInt();
int cnt=0;
int next =N;
while(true){
next = func(next);
cnt++;
if(N==next){
break;
}
}
System.out.println(cnt);
}
private static int func(int n){
int next_num=0;
if(n>=10){
//sum of each position
int position_sum = n/10 + n%10;
int position_sum_last = position_sum%10;
next_num = (n%10)*10 + position_sum_last;
}
if(n<10){
next_num = n*10 + n;
}
return next_num;
}
}
|
cs |
μκ² λ κ²
char -> int λ‘ λ³νν λ -0 κ°μ μ°μ°μ ν΄μ£Όλ©΄ λλ€κ³ νλλ° λλ μ μλμλ€.
κ·Έλ¦¬κ³ λ μ리μμ κ° μ리 ν©μ ꡬν λ N%10 + N/10μ νλ©΄ μ½κ² ꡬν μ μμλ€.
λ°μν