#C5701. Employee ID Badge Sorting
Employee ID Badge Sorting
Employee ID Badge Sorting
In this problem, you are given information about employee badges. Each badge lists the employee's ID and the floor on which they work. You need to group and sort the employee IDs according to the following rules:
- Group the employee IDs by the floor they work on.
- Sort the groups in ascending order of the floor number.
- Within each group, sort the employee IDs in ascending order.
More formally, for a test case with N employees having pairs \((id_i, floor_i)\), the required order is obtained by sorting by the pair \((floor_i, id_i)\) in lexicographical order.
inputFormat
The input is provided via stdin
with the following format:
T N₁ employee_id₁ floor₁ employee_id₂ floor₂ ... (N₁ lines) N₂ ... (employee details for test case 2) ...
Where:
- T is the number of test cases.
- For each test case, the first line contains an integer N, the number of employees.
- Each of the next N lines contains two space-separated integers: the employee ID and their floor number.
Note: All numbers are integers.
outputFormat
For each test case, output a single line to stdout
containing the sorted employee IDs, separated by a single space. The sorting must be done first by the floor number in ascending order and then by the employee ID in ascending order within the same floor group.
2
3
101 2
102 1
103 2
4
201 1
202 2
203 1
204 2
102 101 103
201 203 202 204
</p>