Earrings
InterviewTime limit1sMemory limit128 MB
Given girl names and 2n-1 confiscation/return records tagged with a number and a letter, find the girl whose number appears only once and thus never got her earring back.
- Level
Easy2 of 10
- Topics
- Hash map, Array, Implementation
- Solved
- No attempts yet
Problem
Many girls at Pascal High School wear earrings that are not allowed by the school rules. Whenever Vice Principal Sneddon sees long, dangling red earrings, he confiscates them.
The vice principal made a numbered list of the girls whose earrings were confiscated. On the back of each confiscated earring, he wrote the girl's number and either A or B, chosen arbitrarily.
After all regular classes and after-school detentions end, the girls visit the vice principal to get their earrings back. Unfortunately, one day he lost the envelope containing the earrings, and one earring could not be found.
Tell the vice principal the name of the angry girl who did not get her earring back.
Input
The input consists of several numbered scenarios. Scenario numbers start at 1 and increase by 1 in input order. Each scenario is given as follows.
- The first line contains the number
nof girls whose earrings were confiscated. (1 ≤ n ≤ 100) - The next
nlines contain the girls' names, one per line. Each name has length at most 60 characters. - The next
2n - 1lines each contain a girl number and the letterAorB, separated by a space. The number matches the order of the vice principal's list, so1means the first girl whose earrings were confiscated. A girl's number appears at most twice, and when it appears a second time, it is paired with the other letter. The first record for a number represents confiscation, and the second record represents return.
A final line containing 0 ends the input. Do not process this line.
Output
For each scenario, output one line containing the scenario number and the name of the girl who did not get her earring back, separated by one space.