#include <stdio.h>
#include <deque>
#include <string.h>
#include <algorithm>
using namespace std;
typedef struct Stu {
int id;
char name[9];
int grade;
} Stu;
deque<Stu> student;
bool com_id(Stu a, Stu b) {
return a.id < b.id;
}
bool com_name(Stu a, Stu b) {
if (strcmp(a.name, b.name) < 0) return true;
else if (strcmp(a.name, b.name) == 0 && a.id < b.id) return true;
return false;
}
bool com_grade(Stu a, Stu b) {
if (a.grade < b.grade) return true;
else if (a.grade == b.grade && a.id < b.id) return true;
return false;
}
int main(int argc, char *argv[]) {
int n, c;
scanf("%d %d", &n, &c);
int i;
for (i = 0; i < n; i++) {
Stu s;
scanf("%d %s %d", &s.id, s.name, &s.grade);
student.push_back(s);
}
if (c == 1) sort(student.begin(), student.end(), com_id);
if (c == 2) sort(student.begin(), student.end(), com_name);
if (c == 3) sort(student.begin(), student.end(), com_grade);
for (i = 0; i < n; i++) {
printf("%06d %s %d\n", student[i].id, student[i].name, student[i].grade);
}
return 0;
}
【PAT甲级】1028. List Sorting (25)
最新推荐文章于 2021-08-22 15:27:55 发布