Couple Ring Match
InterviewTime limit1sMemory limit1024 MB
Find every ring feature worn by exactly two people and print those pairs of names, ignoring anyone whose feature is '-'.
- Level
Easy3 of 10
- Topics
- Hash map, Implementation
- Solved
- No attempts yet
Problem
Jonghyeon wants to find out how many couples there are at his school. Couples wear a distinctive ring on their left ring finger as a couple ring. After noticing this, Jonghyeon decided to check the left ring finger of every enrolled student. If exactly two people wear rings with the same feature, Jonghyeon considers those two a suspected couple. For the given input, find the people Jonghyeon considers suspected couples.
Input
The first line contains , the number of people whose left ring finger Jonghyeon checks. () Each of the next lines contains a person's name and the feature of their ring , separated by a space. If the person is not wearing a ring, is given as -. Both and are strings of length at most 50. All names are distinct. All names and ring features consist of English letters, digits, and underscores (_).
Output
On the first line, print the number of suspected couple pairs. If there is at least one pair, print each pair on its own line starting from the second line, with the two names separated by a space. The order does not matter.