WolfDelaymaster
SRM 593 · 2013-06-25 · by tozangezan
SRM 593 · 2013-06-25 · by tozangezan · String Manipulation, String Parsing
Problem Statement
Problem Statement
Wolf Sothe is playing the game Delaymaster.
In this game, he can create new words according to the following rules:
String str.
Return "VALID" if str is a valid word and "INVALID" otherwise.
Note that the return value is case-sensitive: you must return the strings "VALID" and "INVALID" in all-uppercase.
- For each positive integer n, the string which consists of n copies of 'w', then n copies of 'o', then n copies of 'l', and finally n copies of 'f' is a valid word.
- The concatenation of two valid words is a valid word.
- Only the words that can be obtained by rules 1 and 2 are valid. There are no other valid words.
- By rule 1, "wolf", "wwoollff", and "wwwooolllfff" are valid words.
- Then, by rule 2, "wolfwwoollff" is a valid word.
- By applying rule 2 twice, "wolfwwoollffwolf" is a valid word.
- The string "wfol" is not a valid word (order matters).
- The string "wwolfolf" is not a valid word (we can only concatenate, not insert one word into another).
- The string "wwwoolllfff" is not a valid word (only two 'o's instead of three).
Constraints
- str will contain between 1 and 50 characters, inclusive.
- Each character in str will be 'w', 'o', 'l' or 'f'.
Examples
0)
"wolf" Returns: "VALID"
The first valid word from the examples in the problem statement.
1)
"wwolfolf" Returns: "INVALID"
The second invalid word from the examples in the problem statement.
2)
"wolfwwoollffwwwooolllfffwwwwoooollllffff" Returns: "VALID"
3)
"flowolf" Returns: "INVALID"
4)
"o" Returns: "INVALID"
Submissions are judged against all 175 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Coding Area
Language: C++17 · define a public class WolfDelaymaster with a public method string check(string str) · 175 test cases · 2 s / 256 MB per case