import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int input = Integer.parseInt(br.readLine());
int a = input/10;
int b = input%10;
int cnt = 0;
int result;
while (true){
cnt++;
result = (b*10) + (a+b)%10;
a = result/10;
b = result%10;
//System.out.println("Step" + cnt + ": " + result + " a: " + a + ", b: " + b);
if(result == input){
break;
}
}
System.out.println(cnt);
}
}
다른 사람꺼 퍼옴
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
sc.close();
int number = n;
int count = 0;
do {
number = number % 10 * 10 + (number / 10 + number % 10) % 10;
count++;
} while (n != number);
System.out.println(count);
}
}
'알고리즘 > acmicpc.net' 카테고리의 다른 글
#5543 (0) | 2020.07.13 |
---|---|
#10039 (0) | 2020.07.13 |
10951&10952 (0) | 2020.07.10 |
10871 (0) | 2020.07.08 |
2439 (0) | 2020.07.08 |