TaroString
SRM 613 · 2013-12-22 · by Witaliy
Problem Statement
Cat Taro has a string S. He wants to obtain the string "CAT" from the string S. In a single turn he can choose any character and erase all occurrences of this character in S. He can do as many turns as he wants (possibly zero).
You are given the
Constraints
- S will contain between 1 and 50 characters, inclusive.
- S will contain only uppercase English letters ('A'-'Z').
"XCYAZTX" Returns: "Possible"
It is possible to obtain string "CAT" in three turns, as follows: Erase all characters 'X' (and obtain the string "CYAZT") Erase all characters 'Y' (and obtain the string "CAZT") Erase all characters 'Z' (and obtain the string "CAT")
"CTA" Returns: "Impossible"
"ACBBAT" Returns: "Impossible"
Note that whenever you are erasing a character, you must erase all its occurrences. In this case, it is not possible to erase the first 'A' and keep the second one.
"SGHDJHFIOPUFUHCHIOJBHAUINUIT" Returns: "Possible"
"CCCATT" Returns: "Impossible"
Submissions are judged against all 96 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class TaroString with a public method string getAnswer(string S) · 96 test cases · 2 s / 256 MB per case