悬2关求条!

P1104 生日

Lots_of @ 2024-10-22 22:45:20

80pts,WA最后一个

#include <bits/stdc++.h>
using namespace std;
#define int long long
struct node{
    string name;
    int y,m,d;
}awa[1000005];
bool cmp(node x,node y){
    if(x.y!=y.y){
        return x.y<y.y;
    }
    else if(x.m!=y.m){
        return x.m<y.m;
    }
    else if(x.d!=y.d){
        return x.d<y.d;
    }
    else{
        return x.y<y.y;
    }
}
signed main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>awa[i].name>>awa[i].y>>awa[i].m>>awa[i].d;
    }
    sort(awa+1,awa+n+1,cmp);
    for(int i=1;i<=n;i++){
        cout<<awa[i].name<<endl;
    }
    return 0;
}

by Nights_watcher @ 2024-10-22 22:49:57

因为sort是用的快排,不能保证相同数据的先后顺序,所以要记录他是第几个输入的,按逆序排序 @Lots_of


by Lots_of @ 2024-10-22 22:59:44

@TooAmazing cmp不是处理了吗


by Lots_of @ 2024-10-22 22:59:57

@Chenhaoyang0318 哦哦哦我才想起来,万分感谢


by Chenhaoyang0318 @ 2024-10-22 23:00:46

@Lots_of f 题目说生日相同的序号大的在前,可以再main函数里给每个人一个序号1~n.排序时的最后一种情况改成x.id>y.id应该就行了


|