有毒

P1093 [NOIP2007 普及组] 奖学金

榴莲菌 @ 2019-11-12 18:47:14

#include<iostream>
#include<algorithm>
using namespace std;
struct node {
    int zf,yw,sx,yy,xh;
} dd[350];
bool cmp(node a,node b) {
    if(a.zf > b.zf) return 1;
    else if(a.zf < b.zf)return  0;
    else {
        if(a.yw > b.yw) return 1;
        else if(a.yw < b.yw) return 0;
        else if(a.xh > b.xh) return 0;
        else return 1;
    }
}
int main() {
    int n;
    cin>>n;
    for(int i=1; i<=n; i++) {
        cin>>dd[i].yw>>dd[i].sx>>dd[i].yy;
        dd[i].xh=i;
        dd[i].zf=dd[i].yw+dd[i].sx+dd[i].yy;
    }
    sort(dd+1,dd+1+n,cmp);
    for(int i=1; i<=5; i++) {
        cout<<dd[i].xh<<" "<<dd[i].zf<<endl;
    }
    return 0;
}

这是改完ac代码

#include<iostream>
#include<algorithm>
using namespace std;
struct node {
    int zf,yw,sx,yy,xh;
} dd[350];
bool cmp(node a,node b) {
    if(a.zf > b.zf) return a.zf > b.zf;
    else if(a.zf < b.zf)return  a.zf < b.zf;
    else {
        if(a.yw > b.yw) return a.zf > b.zf;
        else if(a.yw < b.yw) return a.zf < b.zf ;
        else if(a.xh > b.xh) return a.zf < b.zf;
        else return a.zf > b.zf;
    }
}
int main() {
    int n;
    cin>>n;
    for(int i=1; i<=n; i++) {
        cin>>dd[i].yw>>dd[i].sx>>dd[i].yy;
        dd[i].xh=i;
        dd[i].zf=dd[i].yw+dd[i].sx+dd[i].yy;
    }
    sort(dd+1,dd+1+n,cmp);
    for(int i=1; i<=5; i++) {
        cout<<dd[i].xh<<" "<<dd[i].zf<<endl;
    }
    return 0;
}

sort 里面return改过很多次了都是不过样例的???


|