Mõttemeister
InterviewTime limit1sMemory limit1024 MB
Given a secret four-digit number and N guesses, print for each guess the count of correct digits (A) and the count of digits in the correct position (B).
- Level
Easy3 of 10
- Topics
- Implementation, Array, Hash map, Brute force
- Solved
- No attempts yet
Problem
Mõttemeister is a board game for two players. The first player thinks of a secret four-digit number, and the second player tries to guess it.
On each turn the guesser proposes a four-digit number. The first player replies with two numbers and : is how many of the digits in the proposed number are correct, and is how many of those are also in the correct position.
The guesser then makes a new proposal, and the game continues until the guesser finds the secret number or the number of turns exceeds a set limit.
For example, suppose the secret number is 5247. For the guess 1234 the reply is (the digits 2 and 4 are correct) and (the digit 2 is in the correct place).
If the proposed number contains repeated digits, each digit is counted as correct only as many times as it appears in the secret number.
Write a program that, given the secret number and a proposed number, finds the correct reply.
Input
The first line contains the secret four-digit number. The second line contains an integer (). Each of the next lines contains one proposed four-digit number. Every number consists of exactly four digits and may have leading zeros.
Output
Print lines. Each line contains two integers and , where () is the number of correct digits in the corresponding proposal and () is how many of them are in the correct position.