#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std;struct Student{ char id[10]; char name[10]; int grade;}stu[100010];bool cmp1(Student a, Student b){ return strcmp(a.id, b.id) < 0;}bool cmp2(Student a, Student b){ if (strcmp(a.name, b.name) != 0) return strcmp(a.name, b.name) < 0; else return strcmp(a.id, b.id) < 0;}bool cmp3(Student a, Student b){ if (a.grade != b.grade) return a.grade < b.grade; else return strcmp(a.id, b.id) < 0;}int main(){ int n, c; scanf("%d%d", &n, &c); for (int i = 0; i < n; i++){ scanf("%s %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; default: sort(stu, stu + n, cmp3); break; } for (int i = 0; i < n; i++){ PRintf("%s %s %d/n", stu[i].id, stu[i].name, stu[i].grade); } return 0;}
新闻热点
疑难解答