10013-super Long sums
Time limit:3.000 seconds
Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem &problem=954
The Problem
The creators of a new programming language d++ have found out which whatever limit for superlongint type they to make, Sometim ES programmers need to operate even larger numbers. A limit of 1000 digits is so small ... You are have to find the sum of two numbers with maximal size of 1.000.000 digits.
The Input
The the ' a ' input file is an integer N, then a blank line followed by n input blocks. The "a" each input blocks contains a single number M (1<=m<=1000000)-the length of the integers (in or Der to make their lengths equal, some leading zeroes can be added). It is followed by this integers written in columns. That's, the next M lines contain two digits each and divided by a. Each of the two given integers isn't less than 1, and the length of their sum does not exceed M.
There is a blank line between input blocks.
The Output
Each output block should contain exactly M digits into a single line representing the sum of this two integers.
There is a blank line between output blocks.
Sample Input
240 44 26 83 733 07 92 8
Sample Output
4750470
Complete code:
/*0.915s*/
#include <cstdio>
int a[1000010], b[1000010], c[1000010];
int main ()
{
int t, M, I, K, carry;
scanf ("%d", &t);
while (t--)
{
scanf ("%d", &m);
for (i = 0; i < M ++i)
scanf ("%d%d", &a[i), &b[i]);
carry = 0;
for (i = M-1 i >= 0;-I.)
{
k = carry + A[i] + b[i];
Carry = k > 9? 1:0;
C[i] = k%;
}
for (i = 0; i < M i++)
printf ("%d", C[i]);
Putchar (ten);
if (t) Putchar (a);
}
return 0;
}
See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/