#C12319. Team Member Role Categorization
Team Member Role Categorization
Team Member Role Categorization
You are given a list of team members, where each team member is represented by a string in the format Name Role
. Your task is to categorize the team members by their roles and output a JSON object (dictionary) with roles as keys and lists of names as values.
The input is provided from standard input (stdin). The first line of input contains an integer n, the number of team members. This is followed by n lines, each containing the team member's "Name Role" details.
For the output, print to standard output (stdout) a JSON formatted string representing a dictionary. The dictionary should have its keys sorted in lexicographical order. For example, the role "Developer" should map to a list of names who are developers, preserving the order of appearance in the input.
Note: If no members are given (n = 0
), output an empty JSON object {}
.
Example:
Input: 4 Alice Developer Bob Developer Charlie Manager Diana Designer</p>Output: {"Designer": ["Diana"], "Developer": ["Alice", "Bob"], "Manager": ["Charlie"]}
inputFormat
The first line contains an integer n (0 ≤ n ≤ 105), representing the number of team members. Each of the following n lines contains a string denoting a team member's name followed by their role, separated by spaces. The role is always the last word in the string.
outputFormat
Output a single line containing a JSON object. The JSON object’s keys are the roles (sorted in lexicographical order) and the corresponding values are lists of names (in their original order) of team members having that role.
## sample4
Alice Developer
Bob Developer
Charlie Manager
Diana Designer
{"Designer": ["Diana"], "Developer": ["Alice", "Bob"], "Manager": ["Charlie"]}