UVa 10013

From Algorithmist
Jump to: navigation, search

10013 - Super long sums[edit]

Summary[edit]

Standard BigNum addition or you can just use 2 big arrays

Explanation[edit]

Method 1 Use BigNum to add, or write from scratch: simply use a string to represent the number and sum.

Method 2 Take 2 arrays of size 1000000 (say result & carry) Start a loop for i = 1 to M (number of digits). Now as you take input add the two numbers and put them in result[i] & if result[i]>10 then substruct 10 from it & store a 1 in the carry[i]. After finishing the input part start a loop for i = M to 0. If there is carry[i] then add a 1 to result[i-1]. Also keep a check for carry here. After the loop ends output the result

Gotchas[edit]

It does not matter whether you print an overflow digit or not. 9 + 9 can either be 8 or 18

Input[edit]

2

4
0 4
4 2
6 8
3 7

3
3 0
7 9
2 8

Output[edit]

4750

470

Solutions[edit]