emyutd @ 2024-10-19 11:41:08
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
struct stu{
string name;
int y,m,d,num;
}stu1[110];
int n;
bool cmp(stu a,stu b)
{
if(a.y==b.y)
{
if(a.m==b.m)
{
if(a.d==a.d)
{
return a.num>b.num;
}
else
{
return a.d<b.d;
}
}
else
{
return a.m<b.m;
}
}
else
{
return a.y<b.y;
}
}
int main()
{
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>stu1[i].name>>stu1[i].y>>stu1[i].m>>stu1[i].d;
stu1[i].num=i;
}
sort(stu1+1,stu1+n+1,cmp);
for(int i=1;i<=n;i++)
{
cout<<stu1[i].name<<' '<<stu1[i].y<<' '<<stu1[i].m<<' '<<stu1[i].d<<endl;
}
return 0;
}
by emyutd @ 2024-10-19 11:43:22
最后输出那里我把每个人的生日都输出了一遍,发现就是按照从大到小的生日排的,但他还是显示错误
by luohoujunyang @ 2024-10-19 11:50:51
@emyutd
if(a.d==a.d)
改为if(a.d==b.d)
by emyutd @ 2024-10-19 13:53:26
@luohoujunyang okok谢谢