杭电ACM HDU 1013

#include <cstdio>
char str[1001];
int main(){
    while(scanf("%s",str)&&(str[0]-'0')){
        int i=0;
        int sum=0;
        while(str[i]){
            sum+=str[i++]-'0';
        }
        int n=sum;
        while(sum>9){
            sum=0;
            while(n>0){
                sum+=n%10;
                n/=10;
            }
            n=sum;
        }
        printf("%d\n",sum);
    }
}

你可能感兴趣的:(杭电ACM HDU 1013)