HD1013

题目链接

http://acm.hdu.edu.cn/showproblem.php?pid=1013

Digital Roots

 

 1 #include<iostream>
2 #include<string>
3 using namespace std;
4 int devide(int n)
5 {
6 int s = 0 ;
7 while(n)
8 {
9 s = s+n%10 ;
10 n = n/10 ;
11 }
12 return s ;
13 }
14 int main()
15 {
16 int s ;
17 string c ;
18 while(cin>>c&&c!="0")
19 {
20 s = 0 ;
21 for(string::size_type i = 0;i < c.size();++i)
22 s = s + c[i]-48 ;
23 while(s/10>0)
24 {
25 s = devide(s) ;
26 }
27 cout<<s<<endl ;
28 }
29 return 0 ;
30 }

 

posted @ 2012-02-04 14:37  _雨  阅读(280)  评论(0编辑  收藏  举报