#C13952. Employee Department Counter
Employee Department Counter
Employee Department Counter
This problem requires you to count the number of employees in each department. You are given a list of employee records. Each record contains the employee's name and the department they belong to. If an employee does not have an assigned department, the department field will be given as None
(as a string). Your task is to ignore such records and count the valid departments only.
Formally, if there are n employees, and each employee record is represented as a line containing a name and a department, then you are to compute a mapping \( f: D \rightarrow \mathbb{N} \) where \( D \) is the set of valid department names and \( f(d) \) is the number of employees in department \( d \). The output should list these departments and their counts in lexicographic order.
inputFormat
The input is provided via standard input (stdin) with the following format:
- The first line contains an integer
n
representing the number of employee records. - Each of the following
n
lines contains two strings separated by a space: the employee's name and the department. If the department is not assigned, it will be given asNone
.
outputFormat
The output should be printed to standard output (stdout). For each department that has at least one employee, print a line containing the department name and the count (separated by a space). The departments must be output in lexicographical order.
## sample5
Alice Engineering
Bob HR
Charlie Engineering
David HR
Eve Marketing
Engineering 2
HR 2
Marketing 1
</p>