https://www.patest.cn/
#include<iostream>
#include<algorithm>
#include<string.h>
#define maxsize 100000
using namespace std;
struct record{
int ID;
char name[9];
int grade;
};
// increasing order according to ID's
bool cmp1(const record& st1, const record& st2){
return st1.ID<st2.ID;
}
//be sorted in non-decreasing order according to names
bool cmp2(const record& st1, const record& st2){
int a = strcmp(st1.name, st2.name);
if(a==0){
return st1.ID<st2.ID;
}
else{
if(a>0){
return true;
}
else
return false;
}
}
//be sorted in non-decreasing order according to grades
bool cmp3(const record& st1, const record& st2){
if(st1.grade==st2.grade){
return st1.ID<st2.ID;
}
else
return st1.grade<st2.grade;
}
int main(){
record stru[maxsize];
int N, C;
while(cin>>N>>C){
for(int i=0; i<N; i++){
cin>>stru[i].ID>>stru[i].name>>stru[i].grade;
}
if(C==1){
sort(stru, stru+N, cmp1);
}
else if(C==2){
sort(stru, stru+N, cmp2);
}
else if(C==3){
sort(stru, stru+N, cmp3);
}
for(int i=0; i<N; i++){
printf("%06d %s %d\n",stru[i].ID,stru[i].name,stru[i].grade);
}
}
return 0;
}