题解(struct)
2025-04-29 20:22:40
发布于:上海
1阅读
0回复
0点赞
#include <iostream>
#include <algorithm>
using namespace std;
struct student {
int chinese, math, english, score, id;
void read(int i) {
cin >> chinese >> math >> english;
score = chinese + math + english, id = i;
}
};
bool cmp(student x, student y) {
if (x.score != y.score) return x.score > y.score;
if (x.chinese != y.chinese) return x.chinese > y.chinese;
return x.id < y.id;
}
student stu[305];
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) stu[i].read(i);
sort(stu + 1, stu + n + 1, cmp);
for (int i = 1; i <= min(n, 5); i++) cout << stu[i].id << " " << stu[i].score << endl;
return 0;
}
这里空空如也
有帮助,赞一个