题目链接:https://www.patest.cn/contests/pat-a-practise/1028
题目解析:PAT甲级再也没有比它更简单排序题了,解析略。
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int N = 100005;
struct Node{
int id;
char name[10];
int grade;
}E[N];
bool cmp1(Node a,Node b){
return a.id < b.id;
}
bool cmp2(Node a,Node b){
return strcmp(a.name,b.name)==0?a.id <b.id:strcmp(a.name,b.name)<0;
}
bool cmp3(Node a,Node b){
return a.grade==b.grade?a.id <b.id:a.grade<b.grade;
}
int main(){
int n,c;
scanf("%d%d",&n,&c);
for(int i=0;i<n;i++){
scanf("%d%s%d",&E[i].id,E[i].name,&E[i].grade);
}
if(c==1) sort(E,E+n,cmp1);
else if(c==2) sort(E,E+n,cmp2);
else if(c==3) sort(E,E+n,cmp3);
for(int i=0;i<n;i++){
printf("%06d %s %d\n",E[i].id,E[i].name,E[i].grade);
}
return 0;
}