RepeatNumberCompare
SRM 712 · 2017-02-20 · by cgy4ever
SRM 712 · 2017-02-20 · by cgy4ever · Brute Force
Problem Statement
Problem Statement
For any two positive integers x and k we can make a new number denoted repeat(x, k) by concatenating k copies of x written in decimal.
For example, repeat(1234,3) = 123412341234 and repeat(70,4) = 70707070.
You are given theint s x1, k1, x2, and k2.
Let v1 = repeat(x1, k1) and v2 = repeat(x2, k2).
Please compare the numbers v1 and v2 and return a String that describes the result of the comparison.
In particular:
You are given the
- Return "Less" if v1 is less than v2.
- Return "Greater" if v1 is greater than v2.
- Return "Equal" if v1 and v2 are equal.
Notes
- The return value is case-sensitive.
Constraints
- x1 will be between 1 and 1,000,000,000, inclusive.
- k1 will be between 1 and 50, inclusive.
- x2 will be between 1 and 1,000,000,000, inclusive.
- k2 will be between 1 and 50, inclusive.
Examples
0)
1234 3 70 4 Returns: "Greater"
v1 = 123412341234 and v2 = 70707070, so we have v1 > v2.
1)
1010 3 101010 2 Returns: "Equal"
This time we have v1 = v2 = 101010101010.
2)
1234 10 456 20 Returns: "Less"
v1 has 40 digits and v2 has 60 digits, so v1 < v2.
3)
5 9 555555555 1 Returns: "Equal"
4)
5 9 555555554 1 Returns: "Greater"
Submissions are judged against all 78 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class RepeatNumberCompare with a public method string compare(int x1, int k1, int x2, int k2) · 78 test cases · 2 s / 256 MB per case