/*
Question: enter some big integers and output the sum of them.
A major error cause is found in this question, that is, initialization at ②.
*/
# Include <cstdio>
# Include <cstring>
Const int nmax= 200;
Struct BigNumber
{
Int data [nMax];
Int len;
BigNumber () {len = 1; memset (data, 0, sizeof (data ));}
BigNumber (char * str) {* this = str ;}
BigNumber & operator = (char * str );
BigNumber operator + (BigNumber & );
Void clearLeadZero ();
Void print ();
};
BigNumber & BigNumber: operator = (char * str)
{
Memset (data, 0, sizeof (data); // ① the latest addition. If you want to set the remaining parts to zero, add this statement!
Len = strlen (str );
Int I;
For (I = 0; I <len; ++ I)
Data [I] = str [len-I-1]-'0 ';
Return * this;
}
BigNumber: operator + (BigNumber &)
{
Int q = 0;
Int I, j;
BigNumber z;
For (I = 0, j = 0; q | I <len | j <a. len; ++ I, ++ j)
{
Int p = data [I] + a. data [j] + q;
Z. data [I] = p % 10;
Q = p/10;
}
Z. len = I;
Z. clearLeadZero ();
Return z;
}
Void BigNumber: clearLeadZero ()
{
While (len> 1 &&! Data [len-1]) -- len;
}
Void BigNumber: print ()
{
Int I;
For (I = len-1; I> = 0; -- I)
Printf ("% d", data [I]);
Printf ("\ n ");
}
Int main ()
{
// Freopen ("f: // data. in", "r", stdin );
Int T;
Scanf ("% d", & T );
BigNumber ans;
While (T --)
{
Ans = "0 ";
Char s [nMax];
While (scanf ("% s", s )! = EOF)
{
If (s [0] = '0' & s [1] = 0)
Break;
Ans = ans + BigNumber (s );
}
Ans. print ();
If (T)
Printf ("\ n ");
}
Return 0;
}
From lhshaoren