Playground/자바문제집

[백준] 1110번

미숫가루설탕많이 2023. 1. 19. 23:42
import java.util.Scanner;

public class Main {
   public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);

      int num = sc.nextInt();
      sc.close();
      int count = 0;
      // 반복문 탈출하기 위한 변수
      int domang = num;

      // 주어진 수가 10보다 작으면 앞에 0 붙여서 두 자리 수로 만들기
      // 먼저 주어진 두 자리 수를 각각 더하기
      // 주어진 수의 오른쪽 수와 앞에서 더해진 수의 오른쪽 수를 이어 붙이기
      // 처음의 값이 나올 때 까지 반복하기
      while (true) {
         num = ((num % 10) * 10) + ((num / 10) + (num % 10)) % 10;
         count++;

         if (num == domang) break;
      }
      System.out.println(count);
   }
}

'Playground > 자바문제집' 카테고리의 다른 글

[백준] 1152번  (0) 2023.01.20
[백준] 10951번  (0) 2023.01.20
[백준] 10952번  (0) 2023.01.19
[백준] 2439번  (0) 2023.01.19
[백준] 2438번  (0) 2023.01.19