#K45167. Reorder Employees
Reorder Employees
Reorder Employees
You are given a list of employees. Each employee is represented by a badge ID and a full name. Your task is to reorder the employees and output them in sorted order. The sorting criteria are:
- Firstly, sort the employees in ascending lexicographical order based on their full names.
- If two employees have the same full name, then sort them by their badge IDs in ascending order.
For example, if an employee with badge ID 101
has the name "John Doe" and another with badge ID 102
has the name "Jane Smith", then after sorting, the one whose name comes first lexicographically will appear earlier. Note that when names include numbers or spaces, compare them as strings.
You may find the following formula useful for comparison of two employees with entries \( (a, A) \) and \( (b, B) \):
Sort by \( (A, a) \) in ascending order, i.e. employee \( x \) comes before employee \( y \) if \[ A_x < A_y \quad \text{or} \quad (A_x = A_y \text{ and } a_x < a_y). \]
inputFormat
The input is given via standard input (stdin) with the following format:
- The first line contains an integer \( n \) representing the number of employees.
- The next \( n \) lines each contain an employee record. Each record consists of a badge ID (an integer), followed by a space, and then the full name of the employee. The full name may contain spaces.
outputFormat
Output the reordered list of employees via standard output (stdout). Each line should contain the badge ID and the full name separated by a single space, following the sorted order defined in the problem.
## sample4
101 John Doe
102 Jane Smith
103 Alice Johnson
104 Bob Brown
103 Alice Johnson
104 Bob Brown
102 Jane Smith
101 John Doe
</p>