Election
InterviewTime limit1sMemory limit128 MB
Count the votes each candidate receives in one riding, ignore unknown names, and report the winner's party or independent, or tie if there is no strict winner.
- Level
Easy3 of 10
- Topics
- Hash map, Implementation, String, Array
- Solved
- No attempts yet
Problem
Canada has a multi-party system of government. Each candidate is generally associated with a party, and the party whose candidates win the most ridings generally forms the government. Some candidates run as independents, meaning they are not associated with any party. Your job is to count the votes for a particular riding and to determine the party with which the winning candidate is associated.
Input
The first line contains a positive integer (), the number of candidates in the riding.
Then pairs of lines follow. In each pair, the first line is the name of the candidate (up to 80 characters), and the second line is the name of the party (up to 80 characters), or the word independent if the candidate has no party. No candidate name is repeated and no party name is repeated. No line contains leading or trailing blanks.
The next line contains a positive integer (), followed by lines, each giving the name of a candidate for which a ballot is cast. Any name not in the list of candidates is ignored.
Output
Output a single line containing one of the following:
- The name of the party with which the winning candidate is associated, if there is a winning candidate and that candidate belongs to a party.
- The word
independentif there is a winning candidate and that candidate has no party. - The word
tieif there is no winner; that is, if no candidate receives more votes than every other candidate.