https://www.acmicpc.net/problem/1110
1110번: 더하기 사이클
0보다 크거나 같고, 99보다 작거나 같은 정수가 주어질 때 다음과 같은 연산을 할 수 있다. 먼저 주어진 수가 10보다 작다면 앞에 0을 붙여 두 자리 수로 만들고, 각 자리의 숫자를 더한다. 그 다음,
www.acmicpc.net
알고리즘 분류
public class PlusCycle_1110 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int input = Integer.parseInt(br.readLine());
int a = 0;
int b = 0;
int temp = 0;
int newNum = 0;
a = input / 10;
b = input % 10;
int count = 0;
while(newNum != input) {
temp = a + b;
newNum = (b * 10) + (temp % 10);
a = newNum / 10;
b = newNum % 10;
count++;
}
if(count == 0) count = 1;
System.out.println(count);
}
}
'프로그래밍 > Algorithm' 카테고리의 다른 글
[코드업] 6091 : [기초-종합] 함께 문제 푸는 날 (0) | 2022.06.06 |
---|---|
[코드업] 6080 : [기초-종합] 주사위 2개 던지기 - 파이썬 (0) | 2022.06.05 |
[백준 2947] 나무 조각 - 자바 (0) | 2022.06.05 |
[백준 1874] 스택수열 - 자바 (0) | 2022.05.26 |
[백준 11866] 요세푸스 문제 0 - 자바 (0) | 2022.05.23 |