题解 | #Digital Roots#

Digital Roots

http://www.nowcoder.com/practice/cef727d0af33479c9fb4a9c120702414

#include<iostream>

using namespace std;

int main()
{
	int n;
	while(cin >> n)
	{
		int x = n;
		while(x / 10 != 0)
		{
			int t = x, sum = 0;
			while(t != 0) {
				sum += t % 10;
				t /= 10;
			}
			x = sum;
		}
		cout << x << endl;
	}
	return 0;
}
全部评论

相关推荐

1 收藏 评论
分享
牛客网
牛客企业服务