CSU - 1161 Sums

来源:互联网 发布:sql随机生成6位数字 编辑:程序博客网 时间:2024/05/22 00:10

题目:

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

40 44 26 83 7

Sample Output

4750

代码:

#include<iostream>using namespace std; int main(){    int n;    cin >> n;    int *list=new int[n];    int a;    for(int i=0;i<n;i++)    {        cin>>a;        list[i]=a;        cin>>a;        list[i]+=a;    }    for(int i=n-1;i>0;i--)    {        if(list[i]>9)        {            list[i]-=10;            list[i-1]+=1;        }    }    list[0] %=10;    for(int i=0;i<n;i++)printf("%d",list[i]);    return 0;}

1 0
原创粉丝点击