SubtractionGenerator
SRM 824 · 2022-02-17 · by misof
Problem Statement
Michal's younger brother Jan is learning how to subtract. Michal would like to generate some non-trivial exercises for him.
You are given the
- Both x and y are between 1 and 10^9, inclusive.
- The difference x-y is exactly equal to result.
- The number y has the same number of digits as result.
- The number x has more digits than result.
Return the
Notes
- The return value should be a int[] with two elements: element 0 should be x and element 1 should be y.
- A valid solution always exists.
- Any valid solution will be accepted.
Constraints
- result will be between 1 and 10^6, inclusive.
47
Returns: {123, 76 }
123 - 76 = 47 Make sure that your x has more digits than the result. For example, the output {95, 48} isn't valid: even though 95 - 48 = 47, 95 doesn't have more digits than 47. Also make sure that you return the bigger number first. The output {76, 123} would also get rejected.
853
Returns: {1234, 381 }
1
Returns: {10, 9 }
2
Returns: {10, 8 }
3
Returns: {10, 7 }
95
Returns: {190, 95 }
Make sure that your y has the same number of digits as the result. For example, the output {103, 8} isn't valid: even though 103 - 8 = 95, 8 doesn't have two digits.
Submissions are judged against all 69 archived test cases, of which 6 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class SubtractionGenerator with a public method vector<int> generate(int result) · 69 test cases · 2 s / 256 MB per case