Problem E
Squirdle
Squirtle has come up with a word game called Squirdle. In the game, Squirtle thinks of a $5-$letter string (where each letter is a distinct lowercase English letter a-z). Squirtle gives you $10$ guesses to figure out his word, and after each guess he will tell you whether each character of the guess was in the right position, wrong position, or not in the string at all. Guess Squirtle’s word in at most $10$ guesses!
Interaction
This is an interactive problem. You will interact with
Squirtle using standard input and output.
To guess a string s, print a line to standard output in the following format:
-
“? s” (where s is a $5$-character string consisting of only lowercase English letters)
Squirtle will respond with a single line of input: a string of length $5$ consisting of the digits $0$, $1$, and $2$. The number at each position gives you information about the character $c$ at the corresponding position in the guess $s$:
-
$0$ – $c$ is not present in the string.
-
$1$ – $c$ is present in the string but at a different position.
-
$2$ – $c$ is the present in the string at the exact same spot.
The interaction ends when you receive the string
“$22222$” (which means you
have guessed the Squirtle’s word correctly) or when you have
used all $10$ guesses.
Your program should terminate after making a correct
guess.
After every guess, make sure to output a newline character and flush the output stream. To do this, use:
-
fflush(stdout) in C;
-
cout.flush() in C++;
-
System.out.flush() in Java;
-
stdout.flush() in Python.
Read | Sample Interaction 1 | Write |
---|
? frogs
00000
? zebra
20201
? zubat
22222