#C13244. Count Employees by Department
Count Employees by Department
Count Employees by Department
You are given a list of employees. Each employee record includes a name
and a department
. Your task is to count the number of employees in each department and output the result in a sorted order.
The input is provided via standard input (stdin) and the output must be printed to standard output (stdout). In particular, if there are zero employees, the program should produce no output.
Hint: Use a map or dictionary structure to count occurrences.
inputFormat
The first line contains an integer n, which represents the number of employees. The following n lines each contain two strings separated by a space: the employee’s name and the employee’s department.
outputFormat
For every department that appears in the input, output a single line containing the department name and the corresponding employee count (separated by a space). The lines must be sorted in alphabetical order of the department names.## sample
5
John HR
Anna Finance
Mike Finance
Sophia HR
Chris Engineering
Engineering 1
Finance 2
HR 2
</p>