일상

1110 : 더하기 사이클

STUDYING,,, 2021. 7. 26. 23:36
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);

		int num = sc.nextInt(); // 입력된 숫자
		int a = 0; // 일의자리수
		int b = 0; // 십의자리수
		int cnt = 0; // 사이클 카운트
		int tmp = 0; // 원래 숫자비교

		tmp = num;

		while (true) {
			if (tmp >= 0) {

				a = tmp % 10 + tmp / 10;
				if (a >= 10)
					a = a % 10;

				b = tmp % 10 * 10;

				tmp = a + b;

				++cnt;

				if (num == tmp) {
					System.out.println(cnt);
					break;
				}

			}

		}

	}
}

'일상' 카테고리의 다른 글

2562 : 최댓값  (0) 2021.07.26
10818 : 최소, 최대  (0) 2021.07.26
10951 : A + B - 4  (0) 2021.07.26
10952 : A + B - 5  (0) 2021.07.26
10871 : X보다 작은 수  (0) 2021.07.26