Description one of the first users of BIT ' s new supercomputer was Chip Diller. He extended his exploration of powers's 3 to go from 0 to 333 and he explored taking various sums of those numbers.
' This supercomputer is great, ' remarked Chip. "I only wish Timothy were" here for see these results. " (Chip moved to a new apartment, once one became available on the third floor of the Lemon Sky Apartments on third Street.)
Input the input would consist of lines of text, each of which contains a single verylonginteger. Each verylonginteger'll be is fewer characters in length, and would only contain digits (no verylonginteger would be n egative).
The final input line would contain a single zero in a line by itself.
Output Your program should output the sum of the verylongintegers given in the input.
Sample Input
123456789012345678901234567890
123456789012345678901234567890
123456789012345678901234567890
0
Sample Output
370370367037037036703703703670
Problem Solving Ideas:
Is the general high-precision addition problem, the only thing to note is that some of the input data will have a leading 0, the data is too dog. I have several rounds of WA. Therefore, the input end cannot be judged by the first of the string. You also have to decide whether the second is a terminator.
AC Code:
#include <iostream> #include <cstdio> #include <cstring> using namespace std;
const int MAXN = 1000;
int SUM[MAXN];
void Sum (char str[maxn]) {int length, NUM[MAXN];
memset (num, 0, sizeof (num));
Length = strlen (str);
for (int i = 0; i < length; i++) Num[i] = str[length-i-1]-' 0 ';
for (int i = 0; i < maxn-1; i++) {Sum[i] + num[i];
if (Sum[i] >=) {sum[i]%= 10;
sum[i+1]++;
}}} int main () {char STR[MAXN];
memset (sum, 0, sizeof (sum));
while (scanf ("%s", str)) {if (str[0] = = ' 0 ' && str[1] = = 0) break;
Sum (str);
} bool Isbegin = FALSE;
for (int i = maxn-1; I >= 0; i--) {if (isbegin) printf ("%d", sum[i]);
else if (Sum[i]) {printf ("%d", sum[i]);
Isbegin = true;
}} if (!isbegin) printf ("0");
printf ("\ n"); REturn 0;
}