Untitled

 avatar
Darin
plain_text
a year ago
2.6 kB
1
Indexable
Never
 [Description]
The main.cpp or Solution.java code provided in the main part is a code that simulates the number baseball game.
    The number baseball game is played by 2 players. The game participants are denoted as Player 1 and Player 2.




①Player 1 thinks of a 4-digit number whose digits are different from each other.
(Let’s call this number the “thought number”. This thought number can start with 0)

② Player 2 assumes and guesses a 4-digit number whose digits are different from each other
(This number is called the “asked number”. The asked number also can start with 0).

③ Player 1 compares the thought and asked number and tells the number of strikes and balls.

④ The number of strikes is the number of digits which are in the thought number and in the asked number respectively and whose positions in both numbers are identical.

⑤ The number of balls is the number of digits which are in the thought number and in the asked number respectively but whose positions in both number are not identical.

⑥ If the thought and asked numbers match with each other, the game is ended.

⑦ If the thought and asked numbers do not match with each other, one will go back to step ② and repeat the process.


For instance, suppose Player 1 thought of a 4-digit number such as ‘1234’.




If Player 2 asks ‘4139’, Player 1 will tell 1 strike and 2 balls.
When the numbers ‘1234’ and ‘4139’ are compared, both numbers contain each ‘1’,‘3’ and ‘4’. Among them, in case of ‘3’ even the position matches with each other. Position ‘1’ and ‘4’, however, do not match.




If Player 2 asks ‘2567’, Player 1 will tell 0 strike and 1 ball.
When the numbers ‘1234’ and ‘2567’ are compared, both numbers contain each ‘2’.But the position of the number does not match.


If Player 2 asks ‘0768’, Player 1 will tell 0 strike and 0 ball.
When the numbers ‘1234’ and ‘0768’ are compared, there is no number that is contained in both.


In the simulation, Player 1 becomes the computer and the thought numbers is given as each test case.


Using the query function, implement the doUserImplementation function or the UserSolution.doUserImplementation method corresponding to Player 2 to guess the thought numbers.


If there is any repeating digit when the query function is called, the test question is considered wrong and each strike and ball will be saved as ‘-1’ and returned.


For further information, refer to the provided source code.