80,WA#6求修

P1104 生日

stOstOkkkOrzOrz @ 2024-10-23 17:02:49

#include<algorithm>
#include<iostream>
using namespace std;

int n;
struct node{
    string s;
    int y,m,d,id;
    bool operator<(const node &a)const{
        if(this->y!=a.y) return this->y<a.y;
        else if(this->m!=a.m) return this->m<a.m;
        else if(this->d!=a.d) return this->d<a.d;
        else this->id>a.id;
    }
}q[105];
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>q[i].s>>q[i].y>>q[i].m>>q[i].d;
        q[i].id=i;
    }
    sort(q+1,q+n+1);
    for(int i=1;i<=n;i++){
        cout<<q[i].s<<"\n";
    }
    return 0;  
}

by stOstOkkkOrzOrz @ 2024-10-23 17:03:21

要疯了


by stOstOkkkOrzOrz @ 2024-10-23 17:04:24

大佬们先回复,蒟蒻要去上whk了,晚上才能回


by Zhengjingwen_mc @ 2024-10-23 17:09:55

哪题啊


by Civilight_Eterna @ 2024-10-23 17:10:32

@stOstOkkkOrzOrz operator最后一个没有return


by Lionel_Messi_10 @ 2024-10-23 17:12:55

#include <bits/stdc++.h>
using namespace std;
struct node{
    string name;
    int y,m,d,num;
}a[105];
bool cmp(node A,node B){
    if(A.y==B.y){
        if(A.m==B.m){
            if(A.d==B.d) return A.num>B.num;
            return A.d<B.d;
        }
        return A.m<B.m;
    }
    return A.y<B.y;
}
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
    cin>>a[i].name>>a[i].y>>a[i].m>>a[i].d;
    a[i].num=i;
    }
    sort(a,a+n,cmp);
    for(int i=0;i<n;i++){
        cout<<a[i].name<<'\n';
    }
    return 0;
}

说句闲话:手搓cmp不香吗?


by nabunana @ 2024-10-23 17:13:05

else this->id>a.id;

少了return


by Lionel_Messi_10 @ 2024-10-23 17:13:20

@Zhengjingwen_mc 题目传送门


by 阿尔萨斯 @ 2024-10-23 17:16:34

重载小于号这里最后一行

else this->id>a.id;

你再看看这句,是不是少了个return


by stOstOkkkOrzOrz @ 2024-10-23 20:47:46

……


by stOstOkkkOrzOrz @ 2024-10-23 20:50:06

Orz,已关


|