Baekjoon Algorithm | Problem 1110: Addition Cycle

Source

https://www.acmicpc.net/problem/1110

Problem

Solve Baekjoon Online Judge problem 1110, Addition Cycle.

Input

Follow the input format and constraints given in the original problem statement.

Output

Print the answer required by the problem.

Sample Input 1

26

Sample Output 1

4

Sample Input 2

55

Sample Output 2

3

Sample Input 3

1

Sample Output 3

60

Sample Input 4

0

Sample Output 4

1

Sample Input 5

71

Sample Output 5

12

Algorithm Classification

  • Math
  • Implementation

Solution

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {

        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            final int n = Integer.parseInt(br.readLine());

            int newNum = n;
            int count = 0;
            do {
                int num1 = (newNum / 10);
                int num2 = newNum % 10;

                int sum = num1 + num2;
                int sum2 = sum % 10;

                newNum = (num2 * 10) + sum2;

                count++;
            } while (n != newNum);

            System.out.println(count);
        }
    }
}