#C13821. Employee Report Generation

    ID: 43402 Type: Default 1000ms 256MiB

Employee Report Generation

Employee Report Generation

This problem requires you to generate a summary report of employees. Given a list of employees, each with a name, age, department, and tenure, you are to compute and output a JSON object containing:

  • average_age: The average age of employees computed as \(\frac{\sum_{i=1}^{n} \text{age}_i}{n}\) (if there are no employees, it is 0).
  • total_employees: The total number of employees.
  • largest_department: The department with the highest number of employees. In the event of a tie, choose the department that reaches the maximum count first in the input order.
  • longest_tenured_employee: The name of the employee with the maximum tenure. In a tie, choose the first one encountered.

The input will be provided via standard input (stdin) and the output should be printed to standard output (stdout) as a JSON string.

inputFormat

The input is given in the following format:

n
name1 age1 department1 tenure1
name2 age2 department2 tenure2
... (n lines in total)

Here, n (an integer) is the number of employees. If n = 0, then there are no employee records.

outputFormat

The output must be a JSON object (printed as a single line) with four keys:

  • average_age: a number (if there are employees, it is the computed average, otherwise 0).
  • total_employees: an integer representing the number of employees.
  • largest_department: a string representing the department with the most employees; if there are no employees, output null.
  • longest_tenured_employee: a string representing the name of the employee with the highest tenure; if there are no employees, output null.
## sample
5
Alice 30 HR 5
Bob 45 Finance 10
Charlie 25 IT 3
David 35 HR 7
Eve 40 IT 8
{"average_age":35,"total_employees":5,"largest_department":"HR","longest_tenured_employee":"Bob"}