FixMultiplication
2019 TCO India Fun · 2019-04-15 · by misof
Problem Statement
You are given the
Notes
- A digit is correct if and only if it produces a valid equation in which A, B, C are positive integers with no leading zeros.
Constraints
- equation will have the form "A*B=C".
- Each of A, B, C will be a nonempty string of between 1 and 4 characters, inclusive.
- Each character in each of A, B, C will be either a digit ('0'-'9') or a question mark ('?').
- There will be exactly one question mark in equation.
- The numbers represented by A, B, C will not have leading zeros.
"42*47=1?74" Returns: 9
We know that 42*47 = 1974, so the missing digit is 9.
"4?*47=1974" Returns: 2
The same equation, another missing digit.
"42*?7=1974" Returns: 4
And again the same equation.
"42*?47=1974" Returns: -1
This test case has no valid solution. The numbers cannot have leading zeros, so we cannot fill in a zero in front of 47.
"2*12?=247" Returns: -1
Two times something will never be 247, so this test case has no solution either.
Submissions are judged against all 163 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class FixMultiplication with a public method int findDigit(string equation) · 163 test cases · 2 s / 256 MB per case