题解
2025-05-03 13:40:12
发布于:江苏
5阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
struct Student {
int id;
int total;
int chinese;
};
int main() {
int n;
cin >> n;
vector<Student> students;
for (int i = 0; i < n; i++) {
int ch, math, en;
cin >> ch >> math >> en;
int total = ch + math + en;
students.push_back({i + 1, total, ch});
}
sort(students.begin(), students.end(), [](const Student& a, const Student& b) {
if (a.total != b.total) {
return a.total > b.total;
}
if (a.chinese != b.chinese) {
return a.chinese > b.chinese;
}
return a.id < b.id;
});
for (int i = 0; i < 5;i++) {
cout << students[i].id << " " << students[i].total << endl;
}
return 0;
}
这里空空如也
有帮助,赞一个