题目描述
pat官网可以过,在这里TLE了哭死
样例
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
struct Student{
string id, name;
int score;
}student[N];
bool cmp1(Student a, Student b) {
return a.id < b.id;
}
bool cmp2(Student a, Student b) {
if (a.name != b.name) return a.name < b.name;
return a.id < b.id;
}
bool cmp3(Student a, Student b) {
if (a.score != b.score) return a.score < b. score;
return a.id < b.id;
}
int main() {
int n ,c;
cin >> n >> c;
for (int i = 0; i < n; i ++ ) {
cin >> student[i].id >> student[i].name >> student[i].score;
}
switch(c) {
case 1: sort(student, student + n, cmp1); break;
case 2: sort(student, student + n, cmp2); break;
case 3: sort(student, student + n, cmp3); break;
}
for (int i = 0; i < n; i ++ ) {
cout << student[i].id << " " << student[i].name << " " << student[i].score << endl;
}
return 0;
}
blablabla
算法1
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla
算法2
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
C++ 代码
blablabla