HOJ 1401 Gigantic Sums 趣题

 

Nowadays, it seems that no matter how long the INT type is in a programming language, some programmers still have to operate even larger numbers. Your task is to help these programmers to find the sum of two integers with up to 1,000,000 digits.

Input

There are several test cases. In this problem, the integers are given in columns. The first line of each test case consists of an integer N(1 <= N <= 1,000,000), the length of integers. It is followed by N lines, containing two integers each. The ith line denotes the ith digit of the first and second integer. The integers might have leading zeroes. You may assume the sum of the two integers will not have more than N digits.

Output

Output a single line with exactly N digits for each test case, which is the sum of the two integers.

Sample Input

4
3 0
6 1
8 3
2 7

Sample Output

3819

 

 

 

 蒽主要是卡内存吧。

然后也思路比较简单(难道是我的方法太低端?)

 

理清思路即可:

Start

    程序开始的时候读入两个数,和记为a,后面两个数字记为c

 

         循环:

 

        接着如果c不是9

            如果a大于10,输出a+1,并且a赋值为c%10

            否则输出a,并且a赋值为

            如此滚动……

 

        如果c是9

            进行dfs,找到第一个加起来不是9的,然后把那个加起来的余数返回给a,并且根据是否进位来决定输出多少个0或者多少个9

            如果dfs过程中读入n对数,就输出n个0或者n个9,并在这之前输出a+1或者a

            记得在读入的个数已经有n个的时候跳出dfs,并把a赋为9,标志位cf=0

 

    最后输出个a

 

 

End

   

#include 
#define rep(i,a,b) for(int i=a;i


 

 

 

 

 

 

 

你可能感兴趣的:(模拟)