#C14335. Employee Data Analyzer

    ID: 43973 Type: Default 1000ms 256MiB

Employee Data Analyzer

Employee Data Analyzer

You are given a CSV data representing a list of employees. The CSV data is provided on standard input in the following format:

N
employee_id,name,department,salary
... (N lines of employee data)
command

The first line contains an integer N which denotes the number of employee records. The second line is the CSV header. The next N lines each contain an employee record with four comma-separated values: employee_id, name, department, and salary. The last line contains a command.

The available commands are:

  • list <department>: List all employees in the given department. Output the employee names in the order they appear, one per line.
  • average <department>: Calculate and output the average salary of the given department. The average salary is computed as \(\displaystyle \text{Average} = \frac{\sum_{i=1}^{n} salary_i}{n}\). Output the result as a float with one decimal place.
  • minmax: Find and output the employee with the highest salary on the first line and the employee with the lowest salary on the second line.

If a department specified in the command does not exist among the employees, or if there are no employees (for the minmax command), output Error (without quotes).

inputFormat

The input is read from standard input and has the following format:

N
employee_id,name,department,salary
record1
record2
... (N records)
command

Here, N is an integer denoting the number of employee records. The header row is always present. Each record is a CSV line with fields:

  • employee_id: a unique identifier.
  • name: the employee's name.
  • department: the department name.
  • salary: the employee's salary (a floating-point number).

The final line specifies the command to execute, as described above.

outputFormat

Output the result to standard output. Depending on the command:

  • For list <department>: output the names of employees in that department, one per line.
  • For average <department>: output the average salary as a floating point number with one decimal place.
  • For minmax: output two lines — the first with the name of the employee with the highest salary, and the second with the name of the employee with the lowest salary.

If the specified department does not exist, or if there are no employees for the minmax command, output Error.

## sample
3
employee_id,name,department,salary
1,John Doe,Engineering,70000
2,Jane Smith,HR,60000
3,Emily Davis,Engineering,75000
list Engineering
John Doe

Emily Davis

</p>