大佬请指教 90分第八个点过不了(求指教

P1093 [NOIP2007 普及组] 奖学金

liuhaopeng666 @ 2023-08-01 09:59:43

代码:```


#include<iostream>
#include<algorithm>
using namespace std;
struct node{
    int id;
    int chinese;
    int maths;
    int english;
    int ans;
    int jilu;
}a[1000];
bool cmp(node a,node b){
    if(a.ans!=b.ans){
        return a.ans>b.ans;
    }
    if(a.ans==b.ans){
        if(a.chinese!=b.chinese){
            return a.chinese>b.chinese;
        }

        if(a.chinese==b.chinese){
            return a.id<b.id;
        }
    }
}
int main(){
    node a[1000];
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i].chinese>>a[i].maths>>a[i].english;
        a[i].ans=a[i].chinese+a[i].maths+a[i].english;
        a[i].jilu=i;
    }
    sort(a+1,a+n+1,cmp); 
    for(int i=1;i<=5;i++){
        cout<<a[i].jilu<<" "<<a[i].ans<<endl;
    }
    return 0;
} 

by qinghaipeng @ 2023-08-01 10:04:13

首页双贴


by liuhaopeng666 @ 2023-08-01 10:15:17

我已AC,原因是cmp中 不是return a.id<b.id; 是 return a.jilu<b.jilu;


by qianniao @ 2023-09-30 16:36:58

哟哟哟今天刷题两次看到你帖子了 太卷了


|