简单题,就简单做,别给自己下套了!
#include <bits/stdc++.h>
using namespace std;
struct student {
string name;
int age;
double score;
student() : name(""), age(0), score(0.0) {}
student(string name, int age, double score): name(name), age(age), score(score) {}
};
int main() {
int n;
cin >> n;
student stu[1001];
for (int i = 0; i < n; i++) {
string name;
int age;
double score;
cin >> name >> age >> score;
stu[i] = {name, age, score};
}
sort(stu, stu+n, [](student a, student b) {
if (a.score == b.score && a.name == b.name) return a.age < b.age;
else if(a.score == b.score) return a.name < b.name;
return a.score < b.score;
});
for (int i = 0; i < n; i++) {
cout << stu[i].name << " " << stu[i].age << " " << stu[i].score << endl;
}
}

京公网安备 11010502036488号