#P8079. Interactive Word Guess Game
Interactive Word Guess Game
Interactive Word Guess Game
In this problem, you are required to implement an interactive word guessing game. In each round, the interactive library will generate a word of length \(5\) from a given dictionary and provide its first letter. You have at most 5 chances to guess the hidden word.
For each guess, you must output a word (of length \(5\)) that exists in the dictionary. If your guess is correct, the round ends immediately. Otherwise, the interactive library returns two boolean arrays \(\texttt{gold}\) and \(\texttt{silver}\):
- \(\texttt{gold}[i]\) for \(0 \leq i < 5\) is \(true\) if and only if the \(i\)th letter of your guess is correct in both character and position.
- \(\texttt{silver}[i]\) (only defined for letters that are not golden) is \(true\) if the letter appears elsewhere in the hidden word among the non-golden positions.
For example:
- If the hidden word is
panic
and your guess ispaper
, thengold[0] = true
(\(p\) is correct) andgold[1] = true
(\(a\) is correct), and all other entries are false. Note that although the secondp
inpaper
appears inpanic
, it is ignored as it is part of the golden letters. - If the hidden word is
apple
and your guess ispaper
, thengold[2] = true
(\(p\) in the third position is correct) andsilver[0] = true
,silver[1] = true
, andsilver[3] = true
because those guessed letters appear in the hidden word in non‐golden positions.
Scoring: You will play \(T = 1000\) rounds in total. The score for each round is determined as follows:
- If any guessed word is not of length \(5\) or is not in the dictionary, you score \(0\) for that round.
- If you guess correctly on the 1st try, you earn \(150\) points; 2nd try: \(120\) points; 3rd try: \(100\) points; 4th try: \(90\) points; 5th try: \(85\) points.
- If all five guesses are wrong, you earn \(0\) for that round.
Your final score will be the minimum of \(100\) and the average score over the \(1000\) rounds.
Interactive Function Interface:
You must implement the following two functions in a single source file named word.cpp
(for C++):
const char *guess(int num_testcase, int remaining_guesses, char initial_letter, bool *gold, bool *silver);
void init(int num_scramble, const char *scramble);
Details:
- The parameter
num_testcase
indicates the current round (\(1 \leq num_testcase \leq T\)). - Each round calls the
guess
function between 1 and 5 times. On the \(j\)th call,remaining_guesses
is \(6-j\) (i.e. from 5 down to 1). - The
initial_letter
is the first letter of the hidden word (a lowercase letter). - For calls with
remaining_guesses == 5
, the arraysgold
andsilver
are not available (may be NULL). For calls withremaining_guesses < 5
, these arrays have size 5. - The string returned by
guess
must be exactly 5 characters long and exist in the dictionary. - The
init
function is called exactly once before any calls toguess
. Its parameters arenum_scramble
(the size of the dictionary) andscramble
, which is a concatenation of all dictionary words (each word is 5 characters, no separators).
Additional files provided include header files and sample executables for testing (e.g. word.h
, word_sample.cpp
, play.cpp
, etc.).
inputFormat
This is an interactive problem. You do not need to read any input from standard input. Instead, implement the functions as specified. The testing framework will call these functions with appropriate parameters.
outputFormat
This is an interactive problem. You do not need to write anything to standard output. Your solution is expected to implement the required functions correctly.
sample
num_testcase: 1
remaining_guesses: 5
initial_letter: a
(scramble string provided in init)
Return value from guess: "apple"