刚开始的时候,代码里有注释,结果CE。
后来,WA,奇了怪了。挺简单的一道题哇。
事实上是我没考虑大整数,不能用int,得用字符处理。
方法二:http://blog.sina.com.cn/s/blog_6ce23f8f0100loc4.html,各个位数的和%9。
# include <stdio.h>
# include <string.h>
int main()
{
int root;
char a;
while(1)
{
root=0;
while(scanf("%c",&a) && a!='\n')
root+=a-'0'; //所有位数上的数字和
if(root==0)
break;
if(root%9==0)
root=9;
else
root=root%9;
printf("%d\n",root);
}
return 0;
}
方法一(C++)