The creators of a new programming language D++ have found out that whatever limit for SuperLongInttype they make, sometimes programmers need to operate even larger numbers. A limit of 1000 digitsis so small... You have to find the sum of two numbers with maximal size of 1.000.000 digits.
Input
The first line of a input file is an integer N, then a blank line followed by N input blocks. The first lineof an each input block contains a single number M (1 ≤ M ≤ 1000000) the length of the integers (inorder to make their lengths equal, some leading zeroes can be added). It is followed by these integerswritten in columns. That is, the next M lines contain two digits each, divided by a space. Each of thetwo given integers is not less than 1, and the length of their sum does not exceed M.
There is a blank line between input blocks.
Output
Each output block should contain exactly M digits in a single line representing the sum of these two integers.
There is a blank line between output blocks.
Sample Input
2
4
0 4
4 2
6 8
3 7
3
3 0
7 9
2 8
Sample Output
4750
470
问题简述:(略)
问题分析:大数计算问题,模拟计算即可。
程序说明:
按位加法计算中,每一位的相是三个数相加,包括进位位,同时得到两个结果,一是本位数字,二是进位。
题记:(略)
参考链接:(略)
/* UVA10013 Super long sums */
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6;
int a[N], b[N];
int main()
{
int n, m, t;
int digit, carry;
cin >> n;
while(n--) {
string ans = "";
cin >> m;
t = m;
while(t--)
cin >> a[t] >> b[t];
carry = 0;
for(int i=0; i<m; i++) {
digit = a[i] + b[i] + carry;
carry = digit / 10;
digit %= 10;
ans += digit + '0';
}
reverse(ans.begin(), ans.end());
cout << ans << endl;
if(n)
cout << endl;
}
return 0;
}