题解
2025-08-05 14:12:41
发布于:上海
0阅读
0回复
0点赞
#include <iostream>
#include <algorithm>
using namespace std;
struct student{
int chinese;
int math;
int english;
int sum;
int id;
}s[1010];
bool cmp(student a, student b){
if(a.sum == b.sum){
if(a.chinese == b.chinese){
return a.id < b.id;
}
else{
return a.chinese > b.chinese;
}
}
else{
return a.sum > b.sum;
}
}
int main(){
int n;
cin >> n;
for(int i=1; i<=n; i++){
cin >> s[i].chinese >> s[i].math >> s[i].english;
s[i].sum = s[i].chinese + s[i].math + s[i].english;
s[i].id = i;
}
sort(s+1, s+n+1, cmp);
for(int i=1; i<=5; i++){
cout << s[i].id << " " << s[i].sum << endl;
}
return 0;
}
这里空空如也
有帮助,赞一个