http://ac.jobdu.com/problem.php?pid=1119
#include <stdio.h>
#include <cstring>
#include <algorithm>
int main(){
//freopen("in/1119.in","r",stdin);
int res[200],num[102],rlen,len,c,x;
char str[102];
memset(res,0,sizeof(res));
rlen = 0;
while(scanf("%s",str)!=EOF && strcmp(str,"0") !=0 ){
memset(num,0,sizeof(num)); // very important
len = (int) strlen(str);
for (int i = len-1; i >=0; --i) {
num[len-1-i] = str[i] - '0';
}
int calen = std::max(rlen,len);
c = 0;
for (int i = 0; i < calen; ++i) {
x = res[i] + num[i] + c;
res[i] = x%10;
c = x/10;
}
rlen = calen;
while(c){
res[rlen++] = c%10;
c /=10;
}
while(res[rlen-1] == 0) rlen--;
}
if(rlen == 0) printf("0\n");
else{
for (int i = rlen-1; i >=0 ; --i) {
printf("%d",res[i]);
}
printf("\n");
}
}