Exact Sum of Real Numbers

Time limit1sMemory limit128 MB

Summary
Add each group of decimal numbers with up to 30 digits exactly and print the unrounded sum with trailing zeros removed.
Level

Medium4 of 10

Topics
Implementation, String, Math
Solved
No attempts yet

Problem

Sanggeun stores a real number in a struct. The struct has an integer array digits that holds 30 digits, an integer decpt that records where the decimal point sits, and a sign field that records + or -. This scheme keeps a value such as -218.302869584 or 0.0000123456789 exactly, with no rounding.

Given several real numbers, write a program that adds them Sanggeun's way and produces the exact sum.

Input

The first line has the number of test cases. Each test case is a list of real numbers, and a single 0 at the end marks where that test case stops. The terminating 0 is not added into the sum.

Every real number in the input has at most 30 digits, and one test case holds at most 100 real numbers.

Output

For each test case print the sum of its real numbers on one line. Never round. Write the sum exactly, stop at the last nonzero digit, and drop the zeros that follow it.

The format obeys these rules.

  • When no fractional digit remains, leave out the decimal point too. A sum of 1290 is written 1290.
  • When the absolute value is smaller than 1, write exactly one 0 in front of the decimal point. Write 0.2, not .2.
  • Do not pad the integer part with leading zeros.
  • Write a leading - only when the sum is negative.
  • When the sum is 0, print 0.

Examples1

  1. Example 1

    Input
    4
    4.12345678900000000005
    -0.00000000012
    0
    -1300.1
    1300.123456789
    0.0000000012345678912345
    0
    1500.61345975
    -202.004285
    -8.60917475
    0
    -218.302869584
    200.0000123456789
    0
    
    Expected output
    4.12345678888000000005
    0.0234567902345678912345
    1290
    -18.3028572383211