zhupinyan @ 2024-09-30 21:03:38
#include <bits/stdc++.h>
using namespace std;
struct xs{
string mane,year,month,day,brithday;
}a[1000];
int main()
{
int i,j,n,m;
cin>>n;
for(i=1;i<=n;i++)
{
cin>>a[i].mane>>a[i].year>>a[i].month>>a[i].day;
if(a[i].month.size()==1)a[i].month="0"+a[i].month;
if(a[i].day.size()==1)a[i].day="0"+a[i].day;
a[i].brithday=a[i].year+a[i].month+a[i].day;
}
for(i=1;i<=n;i++)
{
for(j=n;j>i;j--)
{
if(a[j].brithday<a[j-1].brithday)
{
swap(a[j].mane,a[j-1].mane);
swap(a[j].year,a[j-1].year);
swap(a[j].month,a[j-1].month);
swap(a[j].day,a[j-1].day);
swap(a[j].brithday,a[j-1].brithday);
}
}
}
for(i=1;i<=n;i++)
{
cout<<a[i].mane<<endl;
}
}
by ni_ju_ge @ 2024-09-30 21:09:48
如果有两个同学生日相同,输入靠后的同学先输出
by ni_ju_ge @ 2024-09-30 21:11:52
所以冒泡时交换的条件应该是 a[j].brithday<=a[j-1].brithday
by ni_ju_ge @ 2024-09-30 21:12:24
@zhupinyan
by zhupinyan @ 2024-09-30 21:41:26
谢
by zhupinyan @ 2024-09-30 21:52:17
AC了谢谢