90分求助

P1093 [NOIP2007 普及组] 奖学金

Gavinzhou @ 2024-04-20 22:21:35

#include<iostream>
using namespace std;
struct s{
    int ID,ch,ma,eng,sum;
    void read(){
        cin>>ch>>ma>>eng;
        sum=ch+ma+eng;
    }
    void print(){
        cout<<ID<<' '<<sum<<endl;
    }
};
s use[1000000];
bool cmp(s y,s x){
    if(y.sum!=x.sum) return x.sum<y.sum;
    if(y.ch!=x.ch) return x.ch<y.ch;
    return x.ID<y.ID;
}
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        use[i].read();
        use[i].ID=i;
    }
    sort(use+1,use+n+1,cmp);
    for(int i=1;i<=5;i++){
        use[i].print();
    }
    return 0;
}

感谢daolao


by Chu_awa_xing @ 2024-05-12 17:35:15

成绩相同并且语文成绩相同,是学号小的排在前面所以

return x.ID<y.ID;

改成

return x.ID>y.ID;

(求关)


by Gavinzhou @ 2024-05-15 21:33:07

@Chu_awa_xing 已关


by Gavinzhou @ 2024-05-15 21:34:57

AC记录


|