POJ1519
水~
题意:求一个数的各个位置上的和,这个和是只有一位的
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include<stdio.h> 2 #include<string.h> 3 const int maxn = 1005; 4 char a[ maxn ]; 5 int main(){ 6 while( scanf("%s",a)!=EOF ){ 7 if( strcmp(a,"0")==0 ) break; 8 int len; 9 len=strlen( a ); 10 int ans=0; 11 for( int i=0;i<len;i++ ){ 12 ans+=( a[ i ]-'0' ); 13 if( ans>=10 ){ 14 ans=ans/10+ans%10; 15 } 16 } 17 printf("%d\n",ans); 18 } 19 return 0; 20 }
keep moving...