Country Leader
Time limit5sMemory limit512 MB
For each test case, pick the name with the most distinct letters, breaking ties by lexicographic order where a space sorts before any letter.
- Level
Easy2 of 10
- Topics
- String, Sorting, Implementation, Hash map
- Solved
- No attempts yet
Problem
The constitution of a country says that the leader is the person whose name contains the greatest number of different letters. The country writes names with the uppercase letters A through Z, and a space inside a name does not count as a letter. For example, GOOGLE contains four different letters: E, G, L and O. APAC CODE JAM contains eight. If those two people are the whole country, the leader is APAC CODE JAM.
If several people have the same number of different letters, the leader is the one whose name comes first in alphabetical order. Names are compared character by character, and a space comes before every letter. For example, A AB C and DEF both contain three different letters, and A AB C comes first, so A AB C is the leader.
Given the names of all citizens, find the leader.
Input
The first line contains the number of test cases . Each test case begins with a line containing the population . The next lines each contain the name of one citizen.
Output
For each test case, print one line in the form Case #x: y, where is the test case number starting from 1 and is the name of the leader.
Constraints
- Each name is at most 20 characters long and consists only of the uppercase letters A through Z and spaces.
- Every name starts and ends with a letter, so every name contains at least one letter.