说是N取10万内,但是maxn取100100仍然最后一个样例超时,后面加一个0就解决了。
#include<cstdio>
#include<algorithm>
#include<string>
#include<iostream>
#define maxn 1001000
using namespace std;
struct node {
int id, grade;
string name;
} stu[maxn];
bool compare1(node a, node b) {
return a.id < b.id;
}
bool compare2(node a, node b) {
if (a.name != b.name) return a.name < b.name;
else return a.id < b.id;
}
bool compare3(node a, node b) {
if (a.grade != b.grade) return a.grade < b.grade;
else return a.id < b.id;
}
int main() {
int N, C;
scanf("%d %d", &N, &C);
for (int i = 0; i < N; i++) {
cin >> stu[i].id >> stu[i].name >> stu[i].grade;
}
if (C == 1) {
sort(stu, stu + N, compare1);
}
else if (C == 2) {
sort(stu, stu + N, compare2);
}
else {
sort(stu, stu + N, compare3);
}
for (int i = 0; i < N; i++) {
printf("%06d ", stu[i].id);
cout << stu[i].name << ' ' << stu[i].grade << endl;
}
}