题解
2024-10-04 09:42:29
发布于:浙江
11阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 3e2 + 5;
struct student{
int chinese, math, english, score, id;
} a[MAXN];
int n;
bool cmp(const student &a, const student &b) {
if(a.score != b.score){
return a.score > b.score;
}
else if(a.chinese != b.chinese){
return a.chinese > b.chinese;
}
return a.id < b.id;
}
int main() {
cin >> n;
for (int i = 1; i <= n; i++){
cin >> a[i].chinese >> a[i].math >> a[i].english;
a[i].score = a[i].chinese + a[i].math + a[i].english;
a[i].id = i;
}
sort(a + 1, a + 1 + n, cmp);
for (int i = 1; i <= 5; i++){
cout << a[i].id << " " << a[i].score << " \n";
}
return 0;
}
这里空空如也
有帮助,赞一个