已过测试点1,但是未得分,难道我用的c++自带的sort排序是不稳定的?
查看原帖
已过测试点1,但是未得分,难道我用的c++自带的sort排序是不稳定的?
1379790
chengwei_hust楼主2024/10/29 12:40
#include<iostream>
using namespace std;
struct student{
    string name;
    int n;
    int m;
    int e;
};
bool cmp(student a,student b){
    return (a.n+a.m+a.e)>(b.n+b.m+b.e);
}
int main(){
    int n;
    cin >> n;
    student a[n];
    for(int i=0;i<n;i++)
        cin >> a[i].name >> a[i].n >> a[i].m >> a[i].e;
    sort(a,a+n,cmp);
    cout << a[0].name << ' ' << a[0].n << ' ' << a[0].m << ' ' << a[0].e;
}
2024/10/29 12:40
加载中...