#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
struct stdt{
char id[8];
char name[10];
int grade;
}stu[100010];
int cmp1(stdt a,stdt b){
return strcmp(a.id,b.id)<0;
}
int cmp2(stdt a,stdt b){
if(strcmp(a.name,b.name)!=0)return strcmp(a.name,b.name)<0;
else return strcmp(a.id,b.id)<0;
}
int cmp3(stdt a,stdt b){
if(strcmp(a.name,b.name)!=0) return a.grade<b.grade;
else return strcmp(a.id,b.id)<0;
}
int main(){
int n,c,i;
scanf("%d%d",&n,&c);
for(i=0;i<n;i++){
scanf("%s %s %d",stu[i].id,stu[i].name,&stu[i].grade);
}
if(c==1) sort(stu,stu+n,cmp1);
else if(c==2) sort(stu,stu+n,cmp2);
else if(c==3) sort(stu,stu+n,cmp3);
for(i=0;i<n;i++){
printf("%s %s %d\n",stu[i].id,stu[i].name,stu[i].grade);
}
return 0;
}
PAT A1028 list sorting (25)
最新推荐文章于 2022-01-13 16:09:10 发布