0
点赞
收藏
分享

微信扫一扫

Digital Roots

互联网码农 2022-05-25 阅读 95
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 }





举报

相关推荐

0 条评论