Programming/백준

[1일 1백준 : 1110번] 더하기 사이클

HyeunJae 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번: 더하기 사이클 (acmicpc.net)

 

1110번: 더하기 사이클

0보다 크거나 같고, 99보다 작거나 같은 정수가 주어질 때 다음과 같은 연산을 할 수 있다. 먼저 주어진 수가 10보다 작다면 앞에 0을 붙여 두 자리 수로 만들고, 각 자리의 숫자를 더한다. 그 다음,

www.acmicpc.net