a.cpp

来自「ACM训练题解 最新版 共8题 ACM训练题解 最新版 共8题」· C++ 代码 · 共 36 行

CPP
36
字号
// Problem A 
// http://acm.uva.es/p/v109/10922.html
// Solution by semiconductor
#include	<cstdio>
#include	<cstring>
using namespace std;

char buf[1001];

void
Solve(int s)
{
	int deg = 1;
	while ( s >= 10 ) {
		int ns = 0;
		while ( s ) {
			ns += s % 10;
			s /= 10;
		}
		s = ns;
		++deg;
	}
	if ( s == 9 ) printf("%s is a multiple of 9 and has 9-degree %d.\n", buf, deg);
	else printf("%s is not a multiple of 9.\n", buf);
}

int
main()
{
	while ( scanf("%s", buf), strcmp(buf, "0") ) {
		int s = 0;
		for ( int i = 0; buf[i]; i++ ) s += buf[i] - '0';
		Solve(s);
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?