P8090 [USACO22JAN] Herdle B
Description
The cows have invented a new puzzle game called Herdle, which has caused a sensation in the cow world.
Every day, a new puzzle is released for the cows to solve. The game uses a $3 \times 3$ grid to represent a section of a farm field, and each cell of the field is occupied by a cow of a specific breed. There are only $26$ possible breeds in total, each represented by a different uppercase letter from A to Z. Players are not told the arrangement of cow breeds in the field—the goal of the game is to determine it through a series of guesses.
In each guess, the cows enter a $3 \times 3$ grid of uppercase letters, representing a possible way the field could be filled with cows. Some cells in the guess may be correct. These cells are highlighted in green, letting the cows know they are correct. Other cells in the guess may contain cows of the correct breed but in the wrong position. These are highlighted in yellow.
The number of yellow-highlighted cells can help indicate how many cows of a certain breed there are. For example, suppose the guess grid contains $4$ cows of breed A, and the answer grid contains $2$ cows of breed A, with no A in the correct position (that is, none of them should be green). In this case, only two of the A's in the guess grid should be highlighted in yellow. More precisely, if the guess grid contains $x$ cows of a certain breed, and the answer grid contains $y \le x$ cows of that breed (not including the cows that are highlighted green due to being in the correct position), then among the $x$ cows in the guess grid, only $y$ cows should be highlighted in yellow.
Given the correct answer grid and a grid representing a guess for that answer, compute the number of cells that should be highlighted green and yellow.
Input Format
The first 3 lines of input give the correct answer grid. The next 3 lines give the guess for that answer.
Output Format
Output two lines. The first line contains the number of cells that should be highlighted in green. The second line contains the number of cells that should be highlighted in yellow.
Explanation/Hint
Sample Explanation 1.
In this example, the O in the middle of the last line is correct, so that cell is highlighted in green. The letter W is in the wrong position, so it is highlighted in yellow.
Sample Explanation 2.
Here, one A is in the correct position, so it is highlighted in green. The remaining A's are not in the correct positions, and since there are two A's in the answer grid, two A's should be highlighted in yellow.
Translated by ChatGPT 5