求助,悬关(只得64分)

P1104 生日

Lu_Yu_hao @ 2024-04-03 21:06:33

#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<climits>
#include<iomanip>
#include<vector>
#include<queue>
#include<map>
using namespace std;
int n;
struct xs{
    string name;
    int year,month,day;
}a[1000005];
bool cmp(xs x,xs y){
    if(x.year!=y.year){
        return x.year>y.year;
    }
    if(x.month!=y.month){
        return x.month>y.month;
    }
    return x.day>y.day;
}
int main(){
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        cin>>a[i].name;
        scanf("%d%d%d",&a[i].year,&a[i].month,&a[i].day);
    }
    sort(a,a+n+1,cmp);
    for(int i=n-1;i>=0;i--){
        cout<<a[i].name<<endl;
    }
    return 0;
}

by watergod @ 2024-04-03 21:12:00

你没处理两个同学生日相同,输入靠后的同学应该先输出的情况(


by Lu_Yu_hao @ 2024-04-03 21:14:16

@watergod 谢了


|