PAT A1028 List Sorting


//ac  
//      ,ifelse    switch   ,  switch      case '1',     case '1',  c    
//switch       !         if else .       switch   ! 
#include<cstdio>
#include<cstring>
#include<algorithm>
//#define LOCAL
using namespace std;
struct Student{
	int id;//6 digits 
	char name[10];
	int grade;//   0~100 
}stu[100010];
bool cmp1(Student a,Student b){
	return a.id<b.id;
}
bool cmp2(Student a,Student b){//       
	int s=strcmp(a.name,b.name);
	if(s!=0) return s<0;
	else return a.id<b.id;
} 
bool cmp3(Student a,Student b){
	if(a.grade!=b.grade) return a.grade<b.grade;
	else return a.id<b.id;
} 
int main(){
	#ifdef LOCAL
	freopen("A1028data.in","r",stdin);
	freopen("A1028data.out","w",stdout);
	#endif
	int n,c;
	scanf("%d %d",&n,&c);
	for(int i=0;i<n;i++){
		scanf("%d %s %d",&stu[i].id,stu[i].name,&stu[i].grade);
	}
	switch(c){
		case 1:sort(stu,stu+n,cmp1);break;
		case 2:sort(stu,stu+n,cmp2);break;
		case 3:sort(stu,stu+n,cmp3);break;
	/*if(c==1)sort(stu,stu+n,cmp1);// id     
	else if(c==2)sort(stu,stu+n,cmp2);//        ,id   
	else sort(stu,stu+n,cmp3);//       ,id  
	      !*/ 
	}		
	for(int i=0;i<n;i++){
		printf("%06d %s %d
",stu[i].id,stu[i].name,stu[i].grade); } return 0; }