求救!Xiebing和Leslie!!!我的代码调了两次都不行!

P1104 生日

xiao_qiu @ 2024-03-23 21:42:19

#include<bits/stdc++.h>
using namespace std;
int n;
char a[110][30];
struct rec
{
    int y,m,d,s,l;
}b[110];
int cmp(rec x,rec z)
{
    if(x.y==z.y)
    {
        if(x.m==z.m)
        {
            return x.d<z.d;
        }
        return x.m<z.m;
    }
    return x.y<z.y;
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%s",a[i]+1);
        scanf("%d%d%d",&b[i].y,&b[i].m,&b[i].d);
        b[i].s=i;
        b[i].l=strlen(a[i]+1);
    }
    sort(b+1,b+n+1,cmp);
    for(int i=1;i<=n;i++)
    {
        for(int j=1;j<=b[i].l;j++)
        {
            cout<<a[b[i].s][j];
        }
        puts("");
    }
    return 0;

by luoguerepp @ 2024-03-31 14:23:11

(如果有两个同学生日相同,输入靠后的同学先输出)

还要考虑输入顺序


by wangtianhao0609 @ 2024-08-02 20:58:55

#include<bits/stdc++.h>
using namespace std;
struct mystruct{
    string name;
    int y,m,d,num;
}a[101];
int n;
bool cmp(mystruct x,mystruct 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.num>y.num;
    }
}
int main(){
    cin >>n;
    for (int i=1;i<=n;i++)
    {
        cin >>a[i].name>>a[i].y>>a[i].m>>a[i].d;
        a[i].num=i;
    }
    sort(a+1,a+n+1,cmp);
    for (int i=1;i<=n;i++)
    {
        cout <<a[i].name;
        if (i!=n)
        {
            cout <<"\n";
        }
    }
    return 0;
}

|