THE CHALLENGEMULTIPLY_STRINGS — Multiply giants.
You are given two positive integers as strings (they can be very large, too large for an integer). Compute their product and print it as a string too. Do not convert the strings to integers.
Input:
- line 1: the string a
- line 2: the string b
Output:
the product a * b as a string.
Example:
123
456
gives
56088
How to break it down:
1. multiplier(a, b): creates an array for the digits of the result (size len(a) + len(b)).
2. Go through both numbers from right to left and add each digit product into the right position, handling the carries.
3. Turn the final array into a string (without useless zeros) and print it.
Giants' challenge: multiplier() does long multiplication "by hand" in an array of digits - never int(a) * int(b), no eval, no import.
Checks (verified automatically before your code runs):
- At least 1 function definition.
- At least 1 call to multiplier().
- Loops may be nested at most 2 levels deep.
- Do not use eval().
- Not allowed: imports.
Hint: the product of a[i] and b[j] goes into cell i + j + 1 of the result array, and the carry goes into i + j.