Problem : 1013 ( Digital Roots )

tips:分析不够仔细,白费了许多功夫。输入数据的范围,平时几乎很少考虑的,这个以后得注意。代码检查不够仔细啊,以后得注意了
#include<iostream>
using namespace std;
void main()
{
int n=0,sum=0;
char s[1000];
while(cin>>s)
{
n=0;
sum=0;
if(strcmp(s,"0")==0)
break;
int len=strlen(s);
for(int i=0;i<len;i++)
{
n+=s[i]-'0';
}
while(n>9)
{
sum=0;
while(n!=0)
{
sum+=n%10;
n/=10;
}
n=sum;
}
cout<<n<<endl; }
}
上一篇:WPF样式


下一篇:js同步-异步-回调