48分求助,re#3#5#6

P1104 生日

1145141919810HOMO11 @ 2023-12-23 20:41:50

#include<bits/stdc++.h>
using namespace std;
struct a{
    string name;
    int year,month,day,id;
};
a all[22];
bool cmp(a sum1,a sum2)
{
    if(sum1.year==sum2.year and sum1.month==sum2.month and sum1.day==sum2.day)
    {
        return sum2.id>sum1.id;
    }
    else if(sum1.year==sum2.year and sum1.month==sum2.month)
    {
        return sum2.day>sum1.day;
    }
    else if(sum1.year==sum2.year )
    {
        return sum2.month>sum1.month;
    }
    else
    {
        return sum2.year>sum1.year;
    }
}
int main()
{
    int b;
    cin>>b;
    for(int i=0;i<b;i++)
    {
        cin>>all[i].name>>all[i].year>>all[i].month>>all[i].day;
        all[i].id=i+1;
    }
    stable_sort(all,all+b,cmp);
    for(int i=0;i<b;i++)
    {
        cout<<all[i].name<<endl;
    }
    return 0;
}

by raozf @ 2023-12-23 20:57:03

数组开小了!


by I_love_AK @ 2023-12-24 06:38:22

a all[22]->a all[1005]


|