백준 1110번  www.acmicpc.net/problem/1110

 

 

풀이

 

두 자리 정수의 합을 일의 자리로, 원래 두 자리 정수를 십의 자리수로 두는 문제이다. 계속해서 원래의 값이 나올 수 있도록 해야 하므로 do-while 문을 이용해서 푼다.

 

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
import java.util.Scanner;
 
public class while_1110 {
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int input = sc.nextInt();
        int x = input;
 
        int cycle = 0;
        
    
            do {
                x = x%10*10 + (x/10+x%10)%10;
                cycle++;
            } while(input!=x);
 
        System.out.println(cycle);
    
    }
    
    public static int cnt(int x) {
        int t = 1;
        if(x/10!=0) {
            x=x/10;
            t++;
        }
    return t;
    }
}
cs
댓글