#include<iostream>
using namespace std;
int root(int s){
if(s<10){
return s;
}
else{
int a=s;
int b=0;
while(a!=0){
b+=a%10;
a=a/10;
}
root(b);
}
}
int main(){
int s;
while(cin>>s&&s!=0){
cout<<root(s)<<endl;
}
}
/*#include <stdio.h>
int main()
{
char s[1000];
int i,sum;
while(scanf("%s",s)!=EOF)
{
if(s[0]==‘0‘)
{
break;
}
sum=0;
for(i=0;s[i]!=‘\0‘;i++)
{
sum+=s[i]-‘0‘;
if(sum>9)
{
sum=sum%10+sum/10;
}
}
printf("%d\n",sum);
}
return 0;
}*/
时间: 2024-10-08 04:57:41