Huawei OD computer test-score ranking (C++ & Java & JS & Python)

describe

Given a sequence of information (names, grades) of some students, please sort their information from high to low or from low to high, with the same grades.

All are processed according to the rules of first entry first.

Examples:
jack 70
peter 96
tom 70
smith 67

From high to low grades
peter 96
jack 70
Tom 70
smith 67

from low to high

smith     67

jack      70

Tom       70

peter     96

Note: 0 represents from high to low, 1 represents from low to high

Data range: Number of people: 1≤�≤200 1≤n≤200 

Advanced: Time complexity: �(�����) O(nlogn), Space complexity: �(�) O(n) 

Enter description:

In the first line, enter the number n of people to be sorted. In the second line, enter an integer indicating the sorting method. In the next n lines, enter their names and grades respectively, separated by a space.

Output description:

Output the name and grades according to the specified method, separated by a space.

Example 1

enter:

3 
0 
fang 90 
yang 50 
ning 70

Output:

fang 90 
ning 70 
yang 50

Example 2

enter:

Guess you like

Origin blog.csdn.net/m0_68036862/article/details/132850545