#C9371. Petition Supporters Summary
Petition Supporters Summary
Petition Supporters Summary
Given a list of supporters, each represented by a string in the format Name, City
, your task is to group the supporters by their city. For each city, the names should be sorted in alphabetical order. The cities themselves should be output in alphabetical order. The input is provided via standard input and the output should be printed to standard output.
Note: If no supporters are provided (i.e. the number of supporters is zero), your program should output nothing.
The desired output format is one line per city. Each line should contain the city's name, followed by a colon, a space, and then a comma separated list of supporters' names sorted in alphabetical order.
For example, given the supporters:
Alice, New York Betty, Los Angeles Charlie, New York Dave, Seattle
The output should be:
Los Angeles: Betty New York: Alice, Charlie Seattle: Dave
inputFormat
The first line contains an integer n (0 ≤ n ≤ 105), representing the number of supporters. The following n lines each contain a supporter’s information in the format Name, City
.
outputFormat
For each distinct city, output a line in the format:
City: supporter1, supporter2, ...
where the city names are printed in alphabetical order and the supporters' names for each city are sorted alphabetically. If n is 0, output nothing.
## sample4
Alice, New York
Betty, Los Angeles
Charlie, New York
Dave, Seattle
Los Angeles: Betty
New York: Alice, Charlie
Seattle: Dave
</p>