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; 
} 


 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值