#include <iostream> #include <string> using namespace std; int main() { string n; while(cin>>n,n!="0") { int s=0,l=n.length(); for(int i=0;i<l;i++) s+=n[i]-‘0‘; while(s>9) s=s/10+s%10; cout<<s<<endl; } return 0; }
#include <iostream>
#include <string>
using namespace std;
int main()
{
string n;
while(cin>>n,n!="0")
{
int s=0,l=n.length();
for(int i=0;i<l;i++) s+=n[i]-‘0‘;
while(s>9) s=s/10+s%10;
cout<<s<<endl;
}
return 0;
}
zju 1115 Digital roots 数字根,布布扣,bubuko.com
原文:http://www.cnblogs.com/2014acm/p/3885941.html