48分#3#5#6求助

P1104 生日

L_hiqwq_L @ 2023-12-29 21:15:39


#include<bits/stdc++.h>
using namespace std;
struct Node{
    string name; 
    int nian,yue,ri,level;
}a[11451];
bool cmp(Node x,Node y){
    if(x.nian!=y.nian){
        return x.nian<y.nian;
    }
    else{
        if(x.yue!=y.yue){
            return x.yue<y.yue;
        }
        else if(x.ri==y.ri&&x.yue==y.yue){
            return x.level<y.level;
        }

    }
}
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i].name>>a[i].nian>>a[i].yue>>a[i].ri;
        a[i].level=i;
    }
    stable_sort(a+1,a+n+1,cmp);
    for(int i=1;i<=n;i++){
        cout<<a[i].name<<endl;
    }
}

by 0oOo0 @ 2023-12-29 21:23:23

@L_hiqwq_L

当月数相同天数不相同你没有考虑到,应该在 cmp 里再写一个特判,判断月数相同天数不相同时怎么排序。


by L_hiqwq_L @ 2023-12-30 17:09:02

@REMENBERNIRVANA 谢谢谢谢谢谢


by L_hiqwq_L @ 2023-12-30 17:17:14

@REMENBERNIRVANA

#include<bits/stdc++.h>
using namespace std;
struct Node{
    string name; 
    int nian,yue,ri,level;
}a[11451];
bool cmp(Node x,Node y){
    if(x.nian!=y.nian){
        return x.nian<y.nian;
    }
    else{
        if(x.yue!=y.yue){
            return x.yue<y.yue;
        }
        else if(x.ri==y.ri&&x.yue==y.yue){
            return x.level<y.level;
        }
        else if(x.yue==y.yue&&x.ri!=y.ri){
            return x.ri<y.ri;
        }
    }
}
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i].name>>a[i].nian>>a[i].yue>>a[i].ri;
        a[i].level=i;
    }
    stable_sort(a+1,a+n+1,cmp);
    for(int i=1;i<=n;i++){
        cout<<a[i].name<<endl;
    }
}

大佬改完以后变成了64分 还有哪些错误吗


|