|시간 제한||메모리 제한||제출||정답||맞은 사람||정답 비율|
|1 초||128 MB||8||7||6||85.714%|
After a long trek through treacherous mountains, Bilbo and the dwarfs have arrived at the West Gate of the mines of Puzzlia, constructed by a mathematically inclined Dwarf King. The gate is of course not open (nothing can be that easy for our heroes), and Dwalin explains to Bilbo that they need to guess a 4-digit number (let’s call it “secret”) correctly to open the gate. He points out 8 geometrical shapes on top of the gate, 4 circles and 4 squares. Every time a guess is made (by standing in front of the gate and speaking each of the digits loudly), some of the squares and the circles will light up. If the guess is correct, then the gate will open; but if the number is not guessed correctly in 10 attempts, then... well, best not to think of such things.
Dwalin explains the rules about how the circles and squares will light up. Let guess denote a guess that is made. For every digit in guess: (1) if it is equal to the corresponding digit in secret (at the same position), then a circle will light up; (2) if it is equal to some digit in secret but at a different position, a square will light up. For example:
The secret (and the guess) may contain duplicate digits. The rule for handling duplicates is simple: a digit in secret can only match one digit in guess (and vice versa), and exact matches supersede out-of-position matches. So we first check for exact matches, and then look for the second type.
Before trying to guess the secret of the gate, Bilbo would like to make sure he understands the process and develops some strategy. He would like your help with this. Specifically, he would like you to write a program that, given two numbers, tells him how many circles and squares would light up.
The first line in the test data file contains the number of test cases (< 100). After that, each line contains one test case: the first number is the secret (provided as an int), and the following number is the guess (provide as an int). Both the numbers are ≤ 9999. Note that the numbers need to be padded with 0’s. For example, if one of the numbers is 1, it needs to be treated as 0001.
For each test case, you are to output the numbers of circles and squares that will light up. Exact format shown below.
5 1234 1111 5678 5678 4444 4444 1234 1211 1122 2211
For secret = 1234 and guess = 1111, 1 circles and 0 squares will light up. For secret = 5678 and guess = 5678, 4 circles and 0 squares will light up. For secret = 4444 and guess = 4444, 4 circles and 0 squares will light up. For secret = 1234 and guess = 1211, 2 circles and 0 squares will light up. For secret = 1122 and guess = 2211, 0 circles and 4 squares will light up.