A deep-space relay station receives two independent readings of the distance to a target beacon. Each reading arrives as a string of decimal digits with no sign, no separators, and no leading zeros (unless the reading is exactly the single digit 0). Because a reading can be far longer than any native 64-bit integer can hold, the station's onboard software adds the two readings together digit by digit, exactly the way you would add two numbers by hand on paper. Compute the exact decimal sum of the two readings.
The input consists of two whitespace-separated tokens:
num1 — the first distance reading, a non-empty string of decimal digits.num2 — the second distance reading, a non-empty string of decimal digits.Print a single line containing the decimal string representing num1 + num2, with no leading zeros (the value zero itself is printed as 0).
num1 and num2 consists only of the digits 0-9.num1 nor num2 contains a leading zero, unless the string is exactly "0".Example 1
Input
99 1
Expected
100
Explanation
Adding 99 and 1 digit by digit from the right: 9+1=10 (write 0, carry 1), 9+0+1=10 (write 0, carry 1), the leftover carry 1 becomes a new leading digit, giving the sum "100".
Example 2
Input
456 77
Expected
533
Explanation
Aligning from the right: 6+7=13 (write 3, carry 1), 5+7+1=13 (write 3, carry 1), 4+0+1=5 (write 5, no further carry), giving the sum "533".
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →