Addition II

Problem #4

Tags: computing instructional

Who solved this?

Previous:Mean, Median, and Mode II Next:Multiplication


Thanks to the advent of modern computers, it is relatively uncommon for large sums to be computed by hand anymore. Computers typically store and report numbers using 15 or 16 significant digits. (The significant digits of a number are the digits that remain after removing all leading or trailing zeros.)

But what if we needed more higher precision, requiring more significant digits? Most of us learned in grade school how to add any two numbers together, regardless of their size. First we write each number on a separate line and align them at the decimal point. Then starting from right to left, we add together each column of digits and write the sum below. If the sum is 10 or greater, then only the "ones" digit is written below and the remaining digits are added to the next column instead.

For example to add together the numbers 123.45 and 67.891...

  123.45
+  67.891
---------
  191.341

Problem Statement

You will be given several large numbers with many significant digits. Add them together and return the result.

Input Data
First line will be Q, the quantity of addends.
Q lines will then follow, each with a single large decimal value.

Answer
Should consist of a single value, being the sum of all given addends.
Do not round nor truncate any significant digits in answer.
Remove any trailing zeroes in final answer.

Example

A small example:

input data:
3
78.98
417.031
1061.1308

answer:
1557.1418   

A larger example:

input data:
3
8078065125742397425972178.9853649996265039417729603
86736685606937281095681417.03122483080662760759158223
616572149741763385076281061.130881133388929405208251746

answer:
711386900474443063597934657.147470963822060954572794276
You need to login to get test data and submit solution.