Cupid
InterviewTime limit1.004sMemory limit512 MB
Filter N users by gender preference and distance limit, sort the matching names lexicographically, and print them or "No one yet".
- Level
Easy3 of 10
- Topics
- Sorting, Implementation
- Solved
- No attempts yet
Problem
Since 1969, the Internet has upended all kinds of industries: retailing, politics, entertainment, and more. Among them, its most profound repercussion may well be on how we choose a mate.
When the Internet first appeared, the notion of meeting someone online seemed pathetic and freakish. Now it has become a necessity for some people, especially those coping with social or geographical constraints. In the United States, 70% of gay people meet their partner online. Other evidence suggests that it helps break down homogeneous groups by boosting interracial and international marriage.
On the other hand, service providers face an inherent conflict of interests: the better the matching for users, the fewer people are left in the service. To keep a sustainable business model, the firms decided to provide premium services, such as "see who liked me". With this, you can save a lot of time answering yes or no for candidates who would not finally like you, hence "not a match".
Now you only have to set your gender preference and maximum geographical distance. (No long-distance relationship in the beginning!) It is time to see your candidates.
Input
The name of a premium user, their gender preference, and their maximum geographical distance are given, separated by a space, in the first line. The maximum geographical distance is an integer. The gender preference is one of 'F', 'FM', 'M', and 'MF', representing the user's preference for two traditional genders: female (denoted by 'F') and male (denoted by 'M'). Both 'FM' and 'MF' mean the user prefers both genders.
In the second line, the number of users is given, .
For the next lines, the name of a user who liked the premium user, their gender (denoted by either 'F' or 'M'), and the geographical distance to the premium user are given in each line, separated by a space.
All the names consist only of alphabet characters and their length is not greater than 10. If there are duplicative names, print as many as they appear.
All the geographical distances and the user's limit of it are represented as an integer between 1 and 20,000 inclusive.
Output
Print the name of users who meet the gender preference and geographical condition of the premium user, in lexicographical order, line by line.
If there is no user who meets them, print "No one yet".