Sums

                                                                   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

题意:英文那么多,貌似看不懂丫。。。。。还好示例很容易看出要做什么。

输入n表示所求数的位数,接下来n行,每行两个0~9的数字,然后你要做的就是求出第一列组成的数与第二列组成的数的和。怎么样,简单吧。。。。但,题目所要求的数很大哦,要用到long long。

#include<iostream> 
using namespace std; 
int main()
{     
	long long n;     
	while(scanf("%lld",&n)!=EOF)     
	{         
		int *a=new int[n];         //用数组a来保存第一列的数字
		int *b=new int[n];         //数组b保存第二列的数字
		int *ans=new int[n];         
		memset(ans,0,sizeof(ans)*(n+1));        //所求的数,置零 
		int i;         
		for(i=0;i<n;i++)         
		{             
			scanf("%d%d",&a[i],&b[i]);         
		}         
		for(i=n-1;i>=0;i--)         
		{             
			ans[i]+=a[i]+b[i];             
			if(ans[i]>=10)
			{                 
				ans[i]-=10;                 
				ans[i-1]+=1;             //大于十要进位,就像列加法算式一样(地球人都知道...)
			}         
		}        
		for(i=0;i<n;i++)            
			printf("%d",ans[i]);       
		cout<<endl;   
	}   
	return 0; 
} 


 

 

 

你可能感兴趣的:(Integer,less,ini,each,output,Numbers)