but none of them seems to help my program.

could someone tell me what am i doing wrong?
i simply read one line, go from end to begining, and if my last digit is >9, i take step like digit = digit - 10, and simply transfer that one level (number?) up on the next digit. that's all. it SHOULD work, works for all of my test inputs, even for those posted on this forum, but i still get WA.

here's my code, i hope someone can help me.
Code: Select all
#include <iostream.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
void main() {
int i,c,cmax,br[11000];
char a[11000];
cmax=0;
for (i=0;i<101;i++) br[i]=0;
while (gets(a)) {
if ((strlen(a)==1) && (a[0]=='0')) break; // end sequence
c=0;
for (i=strlen(a)-1;i>-1;i--) {
if (( ((int)a[i]-48) + br[c]) > 9) {
br[c] += ((int)a[i]-48) - 10;
br[c+1]++;
cmax=c+1;
while (br[cmax]>9) {br[cmax] -= 10; br[++cmax]++;}
}
else br[c] += ((int)a[i]-48);
c++;
}
} // end of while
c=1;
for (i=100;i>-1;i--) if ((br[i]!=0)&&(c==1)) {cmax=i+1; c=0;}
for (i=cmax-1;i>-1;i--) cout << br[i];
cout << endl;
}