Hangman
SRM 190 · 2004-04-06 · by dgarthur
Problem Statement
- - He begins by writing down 5 blanks, indicated here by dashes: "-----".
- - Suppose you first guess the letter 'A'. Then, your brother would reveal the one instance of 'A' in the word: "----A".
- - Suppose you next guess the letter 'N'. Then, your brother would reveal both instances of 'N' in the word: "N-N-A".
- - Suppose you next guess the letter 'E'. Then, your brother would reveal nothing new since 'E' is not in the word: "N-N-A".
Constraints
- feedback will contain between 1 and 50 characters inclusive.
- Each character in feedback will be either a capital letter ('A'-'Z') or a dash ('-').
- words will contain between 1 and 50 elements inclusive.
- Each element in words will contain between 1 and 50 characters inclusive.
- No two elements in words will be equal.
- Each character in each element of words will be a capital letter ('A'-'Z').
"N-N-A"
{"NINJA", "NINJAS", "FLIPS", "OUT", "FRISBEE"}
Returns: "NINJA"
As described above, this feedback is consistent with "NINJA" after 'A' and 'N' have been guessed. It is not consistent with "NINJAS", since there are only 5 letters in feedback.
"B--B--"
{"BRINGS", "BARBED", "BUBBLE"}
Returns: "BARBED"
The only correct letter you have guessed is 'B'. If your brother had chosen the word, "BRINGS", then feedback would have been "B-----", and if your brother had chosen the word, "BUBBLE", then feedback would have been "B-BB--". This leaves only the possibility that your brother chose "BARBED", which is, in fact, consistent.
"---------"
{"MONKEY", "FORCE", "IS", "GAINING", "STRENGTH"}
Returns: ""
feedback is consistent with all nine-letter words, but there are no nine-letter words.
"-AAA--"
{"CAAABB", "BAAACC"}
Returns: ""
feedback is consistent with both words.
"---H-O-H-B-OPHOB--"
{"ROSACEA", "GYROVAGUE", "SHACONIAN", "ALTITONANT",
"BRACHIATION", "CERCOPITHECAN", "SCOLECOPHAGOUS",
"RESISTENTIALISM", "SLUBBERDEGULLION",
"AICHMORHABDOPHOBIA", "SPECTOCLOACAPHOBIA",
"ULTRACREPIDARIANISM", "HIPPOPOTOMONSTROSESQUIPEDALIAN",
"CHARGOGGAGOGGMANCHAUGGAGOGGCHAUBUNAGUNGAMAUGG"}
Returns: "AICHMORHABDOPHOBIA"
Your brother has a big vocabulary.
Submissions are judged against all 76 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class Hangman with a public method string guessWord(string feedback, vector<string> words) · 76 test cases · 2 s / 256 MB per case