本文主要是介绍1028. List Sorting (25) PAT甲级,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
传送门
#include<stdio.h>
#include<algorithm>
#include<string.h>
#define MAX_N 100100using namespace std;struct Student{int id;char name[15];int grade;
}stu[MAX_N];bool cmp1(struct Student a,struct Student b){return a.id<b.id;
}bool cmp2(struct Student a,struct Student b){if(strcmp(a.name,b.name)!=0) return strcmp(a.name,b.name)<0;return a.id<b.id;
}bool cmp3(struct Student a,struct Student b){if(a.grade!=b.grade) return a.grade<b.grade;else return a.id<b.id;
}
int main(){int n;int choice;scanf("%d%d",&n,&choice);for(int i=0;i<n;i++){scanf("%d %s %d",&stu[i].id,stu[i].name,&stu[i].grade);}switch(choice){case 1:sort(stu,stu+n,cmp1);break;case 2:sort(stu,stu+n,cmp2);break;case 3:sort(stu,stu+n,cmp3);break;}for(int i=0;i<n;i++){printf("%06d %s %d\n",stu[i].id,stu[i].name,stu[i].grade);}
}
这篇关于1028. List Sorting (25) PAT甲级的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!