90分求调!!!

P1093 [NOIP2007 普及组] 奖学金

ptsxlhs @ 2024-07-02 15:39:22

提交结果

代码:

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

struct jxj{
    int id,a,b,c,sum=0;
};
bool cmp(jxj p1,jxj p2){
    if(p1.sum!=p2.sum){
        return p1.sum>p2.sum;
    }
    if(p1.a!=p2.a){
        return p1.a>p2.a;
    }
    return p1.id>p2.id;
}
int main(){
    int n;
    jxj px[400];
    cin>> n;
    for(int i = 1; i<=n; i++){
        cin>> px[i].a >> px[i].b >> px[i].c;
        px[i].id=i;
        px[i].sum=px[i].a+px[i].b+px[i].c;
    }
    sort(px+1,px+n+1,cmp);
    for(int i = 1; i<=5; i++){
        cout<< px[i].id << " " << px[i].sum <<endl;
    }
    return 0;
}

by ptsxlhs @ 2024-07-02 15:40:44

调完记得@我 QWQ


by Tiffake @ 2024-07-02 15:47:53

@ptsxlhs 如果总分和语文成绩都相等,按学号从小到大排。


by Tiffake @ 2024-07-02 15:48:47

@ptsxlhs 也就是:

bool cmp(jxj p1,jxj p2){
    if(p1.sum!=p2.sum){
        return p1.sum>p2.sum;
    }
    if(p1.a!=p2.a){
        return p1.a>p2.a;
    }
    return p1.id<p2.id;//Here
}

by ptsxlhs @ 2024-07-02 15:56:41

@Tiffake 过了!!!谢!!!

壶关吗???

反正我关了。


by ptsxlhs @ 2024-07-02 15:57:49

^v^


by shenyuhan28 @ 2024-07-09 21:05:27

@Tiffake 感谢\ 劳资也90,经提点也AC了!!\ 壶关吗?\ 反正我关了


by Leo_Ye @ 2024-07-11 22:14:47

@Tiffake 感谢!!!


|