#C7982. Sort Students by Grade and Name
Sort Students by Grade and Name
Sort Students by Grade and Name
You are given multiple test cases. Each test case begins with an integer \( n \) which indicates the number of student records that follow. Each record contains a student's name and grade separated by a space. The input terminates when \( n = 0 \) is encountered.
For every test case, sort the students as follows:
- Primary key: Grade in descending order.
- Secondary key: Name in ascending lexicographical order if grades are equal.
Output the sorted student records for each test case, each on a new line.
inputFormat
The input consists of multiple test cases. Each test case starts with an integer \( n \) (\( n \ge 0 \)) on a single line. If \( n > 0 \), it is followed by \( n \) lines, each containing a student's name and grade (an integer) separated by a space. The input terminates with a test case where \( n = 0 \), which should not be processed.
outputFormat
For each test case, output the sorted student records, one per line. The students should be sorted in descending order by grade, and if two students have the same grade, they should be sorted in ascending alphabetical order by their name.
## sample5
Alice 88
Bob 95
Charlie 88
David 75
Eve 95
3
Alex 92
Kim 92
Zoe 92
0
Bob 95
Eve 95
Alice 88
Charlie 88
David 75
Alex 92
Kim 92
Zoe 92
</p>