0
点赞
收藏
分享

微信扫一扫

hdu 1013

#include<iostream> 

 #include<cstdio> 

 using namespace std; 

 char str[10001]; 

 int main() 

 { 

     while(~scanf("%s",&str)&&str[0]!='0') 

     { 

         int ans=0; 

         for(int i=0;str[i]!='\0';i++) 

             ans+=str[i]-'0'; 

         while(ans>9) 

       { 

         int sum=0; 

         while(ans) 

         { 

           sum+=ans%10; 

           ans/=10; 

         } 

         ans=sum; 

       } 

       printf("%d\n",ans); 

     } 

     return 0; 
}
/****感觉完全水题,不过稍微要注意的是,因为数字很大,所以要换成字符串输入(虽然题目没给出数据范围)
一天写了三题,,
,还不错,保持下去、

举报

相关推荐

0 条评论