Reveals
Time limit1sMemory limit512 MB
Given the people in a house and the names seen outside, find the culprit by applying seven priority rules in order.
- Level
Easy2 of 10
- Topics
- Implementation, Hash map, Sorting
- Solved
- No attempts yet
Problem
Hweeh...
Someone took advantage of the darkness and ate Swi's enormous cake!
Swi loves cake. As usual, Swi set a huge cake bought from a nearby shop on the table and was admiring it. But the room was so warm that Swi fell asleep, and when Swi woke up, the cake was gone!
When the incident happened, there were Swi and other people in the house. The culprit is one of the people in the house at that time.
Swi asked around and collected the names of people who were seen somewhere other than the house at the time of the incident.
This case follows the principles of detective fiction, so the culprit can be deduced by the following rules.
- The rules below are applied in priority order. If two or more rules identify a culprit at the same time, the rule with the smaller number takes precedence.
- Dongho is a villain. If
donghowas in the house at the time of the incident,donghois the culprit regardless of the sightings. - If exactly one person in the house has no sighting, that person is the culprit by elimination.
- If a person named
buminwith no sighting was in the house, that person is the culprit. - If a person named
cakewith no sighting was in the house, that person is the culprit, since the cake is a lie (The cake is a lie). - If a person named
lawyerwith no sighting was in the house, that person is the culprit, since lawyers are always the culprit. - People whose names come first alphabetically find it easier to sneak cake. Among the people in the house other than Swi, the one with no sighting and the alphabetically smallest name is the culprit.
Swi fell asleep in the room with the cake, so Swi was not seen anywhere else.
Each name is unique, and no two people share a name.
A person may have been seen several times, and a person who was seen may have been outside the house at the time of the incident.
Find the culprit who ate Swi's cake.
Input
The first line contains the message that Swi's cake is missing. (swi's cake is missing!)
The second line contains the number of people in the house, not counting Swi.
The next lines each contain the name of one of those people, one name per line.
The next line contains the number of sightings .
The next lines each contain the name of a person seen outside the house at the time of the incident.
Output
Print the name of the culprit who ate Swi's cake, according to the rules.
Constraints
- Every name is a string of 1 to 8 lowercase English letters.
- The culprit can be uniquely identified using the rules in the problem.