按位求和 CSU - 1161 Sums

Description

Sometimes Ziwen need to operate even larger numbers. A limit of 1000 digits is so small… You have to find the sum of two numbers with maximal size of 1 000 000 digits.

Input

The first line contains a single integer N that is the length of the given integers(1 ≤ N ≤ 1 000 000). It is followed by these integers written in columns. That is, the next N lines contain two digits each, divided by a space. Each of the two given integers is not less than 0, and the length of their sum does not exceed N. The integers may contain leading zeroes.

Output

Output exactly N digits in a single line representing the sum of these two integers.

Sample Input

4
0 4
4 2
6 8
3 7

Sample Output

4750

代碼:

#include<iostream>
//Sums CSU - 1161
using namespace std;
int array1[2000010];
int main() 
{
	int N;
	cin >> N;
	//int array[2000010];
	for (int i = 0; i < N; i++)
	{
		cin >> array1[i] >> array1[i + 1000000];//array指向不明確
	}
	
	int temp, b=0;//暫時保存兩位之和,b保存十位上的數
	for (int i = N-1; i >= 0; i--)
	{
		temp = array1[i] + array1[i + 1000000] + b;//加上b哦
		array1[i] = temp % 10;
		b = temp / 10;
	}

	for (int i = 0; i < N; i++)
	{
		cout << array1[i];
	}

	return 0;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章