Digital Roots

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cstring>
 4 #include <string>
 5 #include <cmath>
 6 using namespace std;
 7 int test(int x)
 8 {
 9     int sum=0;
10     while(x){
11         sum+=x%10;
12         x/=10;
13     }
14     sum+=x;
15     return sum;
16 }
17 int main()
18 {
19     int n;
20     while(cin>>n){
21         if(n<10) cout<<n<<endl;
22         else{
23             while(n>=10){
24                 n=test(n);
25             }
26             cout<<n<<endl;
27         }
28     }
29     return 0;
30 }

 

posted @ 2018-05-21 21:12  wydxry  阅读(192)  评论(0编辑  收藏  举报
Live2D