32分红温了

P1104 生日

xuyi20110411 @ 2024-08-29 18:40:23


#include<bits/stdc++.h>
using namespace std;
int n;
struct caoi{
    string k;
    int a,b,c,l;
}s[222222];
bool cmp(caoi x,caoi y){
    if(x.a!=y.a)return x.a<y.a;
    else{
        if(x.b!=y.b)return x.b<y.b;
        else if(x.a!=y.a)return x.c<y.c;
        else return x.l>y.l;
    }
}
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>s[i].k>>s[i].a>>s[i].b>>s[i].c;
        s[i].l=i;
    }
    stable_sort(s+1,s+1+n,cmp);
    for(int i=1;i<=n;i++)cout<<s[i].k<<endl;
    return 0;
}

by LEZ2012 @ 2024-08-29 18:41:24

qp


by SRp1022 @ 2024-08-29 18:46:52

#include<bits/stdc++.h>
using namespace std;
int n;
struct caoi{
    string k;
    int a,b,c,l;
}s[222222];
bool cmp(caoi x,caoi y){
    if(x.a!=y.a)return x.a<y.a;
    else{
        if(x.b!=y.b)return x.b<y.b;
        else if(x.c!=y.c)return x.c<y.c;
        else return x.l>y.l;
    }
}
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>s[i].k>>s[i].a>>s[i].b>>s[i].c;
        s[i].l=i;
    }
    stable_sort(s+1,s+1+n,cmp);
    for(int i=1;i<=n;i++)cout<<s[i].k<<endl;
    return 0;
}

@xuyi20110411, 代码第十三行, 把

else if(x.a!=y.a)return x.c<y.c;

改为

else if(x.c!=y.c)return x.c<y.c;

其余部分没有问题


by xuyi20110411 @ 2024-08-29 19:08:00

@SRp1022 谢谢


|