Little Jay

[C++] 백준 1110번 - 더하기 사이클 본문

알고리즘/BOJ

[C++] 백준 1110번 - 더하기 사이클

Jay, Lee 2021. 9. 3. 13:32
#include <iostream>
using namespace std;

int main() {

	ios::sync_with_stdio(false);
	cin.tie(0);

	int number, result;
	int x, y, z, w;
	int count = 0;

	cin >> number;
	result = number;

	while (true) {
		x = number / 10;
		y = number % 10;
		z = (x + y) % 10;
		w = (y * 10) + z;
		number = w;
		count++;

		if (w == result)
			break;
	}

	cout << count << "\n";

	return 0;
}

'알고리즘 > BOJ' 카테고리의 다른 글

[C++] 백준 1065번 - 한수  (0) 2021.09.05
[C++] 백준 5052번 - 전화번호 목록  (0) 2021.09.04
[C++] 백준 1789번 - 수들의 합  (0) 2021.09.02
[C++] 백준 2512번 - 예산  (0) 2021.09.02
[C++] 백준 5622번 - 다이얼  (0) 2021.09.02
Comments