LeftToRightGame
2018 TCO Fun 3A · 2018-04-20 · by misof
Problem Statement
Alice and Bob are playing a simple game. They take alternating turns writing the digits of a positive integer, from the left to the right. Alice starts. The number is not allowed to start with a zero, hence Alice must choose one of the digits 1 through 9 as her first move.
The game ends when the number has exactly length digits. Bob wins the game if that number is divisible by divisor. Alice wins in all other cases.
You are given the
Constraints
- length will be between 1 and 1000, inclusive.
- divisor will be between 1 and 1000, inclusive.
4 10 Returns: "Bob"
Alice and Bob are creating a 4-digit number. Bob wins if the number ends up being divisible by 10. As he is the one who will write down the last digit of the number, he has a very obvious winning strategy.
3 1000 Returns: "Alice"
A positive three-digit integer will never be divisible by 1000. Alice wins this game regardless of how she and Bob play it.
2 3 Returns: "Bob"
147 47 Returns: "Alice"
7 3 Returns: "Alice"
Submissions are judged against all 142 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class LeftToRightGame with a public method string whoWins(int length, int divisor) · 142 test cases · 2 s / 256 MB per case