70分,蒟蒻求助!!

P1093 [NOIP2007 普及组] 奖学金

shengsimiao @ 2023-12-30 11:51:49

蒟蒻求助啊啊啊

测试样例都对 不知道错哪了

感谢解答的大神

本人小白蒟蒻

弱zhi错误请见谅

大神快来解答吧

再不来我作业就要交不上了啊啊啊

公主王子请解答

解答必关

#include<bits/stdc++.h>
using namespace std;

struct b{
    int ch;
    int ma;
    int en;
    int sum;
    int id;
}arr[1010];
bool cmp(b a,b c){
    if(a.sum != c.sum){
        return a.sum>c.sum;
    }
    return a.id<c.id;
}
int b[1010];
int main(){
    int n;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> arr[i].ch;
        cin >> arr[i].ma;
        cin >> arr[i].en;
        arr[i].sum=arr[i].ch+arr[i].en+arr[i].ma;
        arr[i].id=i+1;
    }
    sort(arr,arr+n+1,cmp);
    for(int i=0;i<5;i++){
        cout<<arr[i].id<<" "<<arr[i].sum<<endl;
    }
    return 0;
}

by Wang_Junduo @ 2024-01-22 15:07:30

bool cmp(student a,student b) { if(a.score!=b.score) return a.score>b.score; else if(a.chinese!=b.chinese) return a.chinese>b.chinese; else return a.id<b.id; }


by Wang_Junduo @ 2024-01-22 15:08:29

sort函数不+1


by shengsimiao @ 2024-03-01 17:53:07

@lovec 感谢已关注


|