從低位慢慢往高位加即可得解。
C++(0.008)
/*******************************************************/
/* UVa 11332 Summing Digits */
/* Author: Maplewing [at] knightzone.studio */
/* Version: 2012/09/17 */
/*******************************************************/
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
int n;
while( scanf( "%d", &n ) != EOF && n ){
while( n/10 ) n = n/10 + n%10;
printf( "%d\n", n );
}
return 0;
}