#C7703. Employee Department Query

    ID: 51604 Type: Default 1000ms 256MiB

Employee Department Query

Employee Department Query

You are given information about employees and their departments, and then a set of queries about departments. Your task is to first build a mapping from each department to the list of employee IDs that belong to that department in the order they appear, and then answer queries by printing, for each queried department, a space-separated list of employee IDs.

The process can be described by the following two functions:

  • process_employee_info: Given a total number $n$ of employees and a list of $n$ records (each record is an employee ID and a department name), generate a dictionary where the key is the department name and the value is a list of employee IDs belonging to that department.
  • query_departments: Given the dictionary from the previous step and a list of department queries, output a list of strings. For each query, output a space-separated list of employee IDs if the department exists; otherwise, output an empty line.

Note that if no employee is associated with a queried department, you should output an empty string for that query.

Input and Output: The input is read from stdin and the output is printed to stdout.

inputFormat

The input is given in the following format:

$n$
ID1 department1
ID2 department2
... (total of n lines)
$q$
query1
query2
... (total of q lines)

where:

  • $n$ is the number of employees.
  • Each employee record consists of an integer employee ID and a department name (a string), separated by a space.
  • $q$ is the number of department queries.
  • Each query is a department name.

outputFormat

For each query in the order given, output a line containing a space-separated list of employee IDs belonging to that department. If a department has no employees or does not exist, output an empty line.

## sample
6
101 marketing
102 sales
103 marketing
104 hr
105 sales
106 engineering
3
marketing
engineering
finance
101 103

106

</p>