AcWing 3375. 成绩排序
原题链接
简单
作者:
171800
,
2024-10-30 20:29:15
,
所有人可见
,
阅读 1
#include<bits/stdc++.h>
using namespace std;
const int N = 1010;
struct node{
int grade;
int id;
string name;
} num[N];
bool cmp1(node a, node b){
if(a.grade == b.grade)
return a.id < b.id;
return a.grade > b.grade;
}
bool cmp2(node a, node b){
if(a.grade == b.grade)
return a.id < b.id;
return a.grade < b.grade;
}
int main(){
int n;
int choice;
cin >> n >> choice;
for(int i = 1; i <= n; i++){
cin >> num[i].name >> num[i].grade;
num[i].id = i;
}
if(choice == 0)
sort(num + 1, num + 1 + n, cmp1);
else
sort(num + 1, num + 1 + n, cmp2);
for(int i = 1; i <= n; i++){
cout << num[i].name << ' ' << num[i].grade << endl;
}
return 0;
}