Problem 335
Bulls and Cows
Medium · 20 pts · String, Hash Table, Counting
Problem
In the Bulls and Cows game you guess a secret number. A bull is a digit of the guess that is correct and in the correct position. A cow is a digit of the guess that appears in the secret but in a different position. Each digit of the secret can be matched at most once: first count all bulls, then count cows among the remaining unmatched digits. Print the hint in the format xAyB, where x is the number of bulls and y the number of cows.
Input
Two lines: the secret and the guess, digit strings of equal length.
Output
Print the hint as xAyB.
Constraints
1 <= length <= 1000
Example input
1807 7810
Example output
1A3B
Explanation
Secret 1807 and guess 7810: the 8 is in the right place (1 bull). The digits 1, 0 and 7 of the guess appear elsewhere in the secret (3 cows). The hint is 1A3B.