#C2883. Employee Database Queries

    ID: 46248 Type: Default 1000ms 256MiB

Employee Database Queries

Employee Database Queries

You are given an employee database management problem. You need to build a system to store employee records and process various queries. Each employee record includes a unique ID, name, department, and salary. The queries you must handle are as follows:

  • Query type 1: Given an employee ID, return the employee's name. If the employee does not exist, output Employee not found.
  • Query type 2: Given a department name, return a space‐separated list of employee IDs working in that department in sorted order. If no employee is found in that department, output an empty line.
  • Query type 3: Given a department name, return the average salary of employees in that department rounded to the nearest integer. If the department does not exist or has no employees, output 0.

Note: All input is read from stdin and all output should be written to stdout, with each query result printed on a new line.

inputFormat

The input is structured as follows:

  1. An integer n (the number of employees).
  2. n lines follow. Each line contains four values separated by spaces: emp_id (integer), name (string), department (string), and salary (integer).
  3. An integer q (the number of queries).
  4. q lines follow. Each query line starts with a query type (integer: 1, 2, or 3):
    • If the type is 1, it is followed by an integer emp_id.
    • If the type is 2, it is followed by a department name (string).
    • If the type is 3, it is followed by a department name (string).

All input is provided via stdin.

outputFormat

For each query, output one line as follows:

  • For query type 1: output the employee's name or Employee not found if the employee does not exist.
  • For query type 2: output the sorted list of employee IDs (separated by spaces) in the given department, or an empty line if no employee exists in that department.
  • For query type 3: output the average salary (rounded to the nearest integer) of the employees in the given department, or 0 if the department does not exist.

Output each answer on a new line to stdout.

## sample
5
1 Alice HR 50000
2 Bob Engineering 60000
3 Carol HR 55000
4 Dave Marketing 45000
5 Eve Engineering 62000
4
1 3
2 HR
3 Engineering
1 6
Carol

1 3 61000 Employee not found

</p>