求助,根本不输出

P1104 生日

Wang_Xu @ 2024-07-18 19:26:01

#include<bits/stdc++.h>
using namespace std;
struct c
{
    string s;
    long long nian,month,day;
};
int main() 
{
    long long n;
    cin>>n;
    c a[n];
    string s1[n];
    for(long long i=1;i<=n;i++)
    {
        cin>>a[i].s>>a[i].nian>>a[i].month>>a[i].day;
    }
    for(long long i=1;i<=n;i++)
    {
        for(long long j=1;j<=n;j++)
        {
            if(a[i].nian>a[j].nian)
            {
                s1[i]=a[j].s;
                if(a[i].nian<a[j].nian)
                {
                    s1[i]=a[i].s;
                } 
                break;
            }
            if(a[i].month>a[j].month)
            {
                s1[i]=a[j].s;
                if(a[i].month<a[j].month)
                {
                    s1[i]=a[i].s;
                }
                break;
            }
            if(a[i].day>a[j].day)
            {
                s1[i]=a[j].s;
                if(a[i].day<a[j].day)
                {
                    s1[i]=a[i].s;
                }
                break;
            }
        }
    }
    for(long long i=1;i<=n;i++)
    {
        cout<<s1[i]<<endl;
    }
    return 0;
}  

by chengjindong @ 2024-07-18 19:41:24

用sort不行吗??再写一个cmp

直接sort(a+1,a+1+n,cmp);


by chengjindong @ 2024-07-18 19:44:57

那几个if很矛盾,

a[i].nian>a[j].nian

a[i].nian<a[j].nian

@wangheyu


by Wang_Xu @ 2024-07-18 19:50:10

感谢,互关


|