-
[1일 1백준 : 1110번] 더하기 사이클Programming/백준 2021. 1. 15. 00:15
#include <iostream> int main(void) { int N, newValue = -1; int first, second, result; int _count = 0; std::cin.tie(NULL); std::ios::sync_with_stdio(false); std::cin >> N; newValue = N; do { if (newValue < 10) { first = 0; second = newValue; } else { second = newValue % 10; first = (newValue - second) / 10; } result = first + second; if (result >= 10) result %= 10; newValue = (second * 10) + result; _count++; } while (newValue != N); std::cout << _count; return 0; }
1110번: 더하기 사이클
0보다 크거나 같고, 99보다 작거나 같은 정수가 주어질 때 다음과 같은 연산을 할 수 있다. 먼저 주어진 수가 10보다 작다면 앞에 0을 붙여 두 자리 수로 만들고, 각 자리의 숫자를 더한다. 그 다음,
www.acmicpc.net
'Programming > 백준' 카테고리의 다른 글
[1일 1백준 : 2577번] 숫자의 개수 (0) 2021.01.16 [1일 1백준 : 10818번] 최소 최대 (0) 2021.01.16 [1일 1백준 : 10951] A+B - 4 (0) 2021.01.14 [1일 1백준 : 2439] 별찍기 - 2 (0) 2021.01.13 [1일 1백준 : 2438] 별찍기 - 1 (0) 2021.01.13