题解阿巴阿巴
2024-02-16 21:57:28
发布于:广东
3阅读
0回复
0点赞
题解如下:
#include <bits/stdc++.h>
using namespace std;
struct fraction{
int num;
int Chinese;
int Math;
int English;
int All;
};
bool cmp(fraction x,fraction y){
if(x.All==y.All){
if(x.Chinese==y.Chinese) return x.num<y.num;
return x.Chinese>y.Chinese;
}
return x.All>y.All;
}
int main(){
int n,fractions[305];
struct fraction students[305];
cin>>n;
for(int i=0;i<n;i++){
students[i].num=i+1;
cin>>students[i].Chinese;
cin>>students[i].Math;
cin>>students[i].English;
}
for(int i=0;i<n;i++){
students[i].All=students[i].Chinese+students[i].Math+students[i].English;
}
//排序
sort(students,students+n,cmp);
for(int i=0;i<5;i++){
cout<<students[i].num<<' '<<students[i].All<<endl;
}
return 0;
}
这里空空如也
有帮助,赞一个