320. Scoring the Guess
A secret and a guess are strings of digits of the same length. Score the guess
and print it as xAyB, where:
x digits that are correct AND in the correct position
y digits present in the secret but in the WRONG position
Each digit of the secret may be used at most once across the whole score, and a
digit already counted as an A cannot also be counted as a B. That single
sentence is the entire problem, and getting it wrong is the classic failure.
Take secret = 1122, guess = 1222. Positions 1, 3 and 4 match, so x = 3. The
remaining secret digit is 1 and the remaining guess digit is 2, which do not
match, so y = 0 and the answer is 3A0B. Counting "how many guess digits
appear anywhere in the secret" instead gives 4 and is wrong.
The reliable method is two passes. First count the exact matches. Then, over the positions that did NOT match, count each digit on both sides and add up the minimum of the two counts for each digit.
Constraints - `1 ≤ length ≤ 100000` - Both strings have the same length. - Every character is a digit `0` to `9`.
Input
The first line contains the secret. The second line contains the guess. Both are digit strings of the same length.
Output
Print the score in the form xAyB, for example 1A3B.
Hints
Four rungs, in order. The last two open once you have submitted an attempt. A wrong one counts.