SistersErasingLetters
TCO11 Round 5 · 2011-05-07 · by maksay
Problem Statement
When a player erases the last letter, the game ends. If the word at the end of the game is lexicographically greater than the word at the beginning, Camomile wins. Otherwise, Romashka wins. You are given a
Notes
- A string X is defined as smaller than a string Y if and only if X is a prefix of Y or X has a smaller character than Y at the first position where they differ.
Constraints
- word will contain between 1 and 50 characters, inclusive.
- Each character in word will be a lowercase letter ('a'-'z').
"topcoder" Returns: "Camomile"
1. Camomile starts by erasing the letter 'c', leaving "topoder". 2. It doesn't matter what Romashka erases on her turn. The possible outcomes of this turn are "topder", "topoer", "topodr" and "topode". In the last outcome, Romashka deletes the last letter and ends the game, but loses. 3. If Romashka doesn't end the game, then Camomile will end it by erasing the last letter. The possible outcomes are "topde", "topoe" and "topod", all of which are lexicographically greater than "topcoder".
"program" Returns: "Romashka"
Camomile can't win here.
"abcd" Returns: "Camomile"
Here, Camomile can only win if she starts by erasing the letter 'a'.
"abc" Returns: "Romashka"
Note that the empty string is lexicographically smaller than any other string.
"easyproblemroundfivetopcoderopentwothousandeleven" Returns: "Camomile"
Submissions are judged against all 108 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class SistersErasingLetters with a public method string whoWins(string word) · 108 test cases · 2 s / 256 MB per case