AcWing 1505. 列表排序
原题链接
简单
作者:
笔尖微凉_7
,
2024-03-03 22:11:37
,
所有人可见
,
阅读 16
#include <bits/stdc++.h>
using namespace std;
typedef struct student{
int id;
string name;
int score;
}stu;
const int N=100001;
stu a[N];
bool comp1(stu x , stu y){
return x.id<y.id;
}
bool comp2(stu x,stu y){
if(x.name!=y.name) return x.name<=y.name;
return x.id<y.id;
}
bool comp3(stu x,stu y){
if(x.score != y.score) return x.score<=y.score;
return x.id<y.id;
}
int main(){
int n,m;
cin >> n >> m;
for(int i = 0 ; i < n ; i++){
cin >> a[i].id >> a[i].name >> a[i].score;
}
switch(m){
case 1:
sort(a,a+n,comp1);break;
case 2:
sort(a,a+n,comp2);break;
case 3:
sort(a,a+n,comp3);break;
}
for(int j = 0 ; j < n ;j++){
printf("%06d %s %d\n",a[j].id,a[j].name.c_str(),a[j].score);
}
return 0;
}