shunxinruyi @ 2024-10-20 21:19:29
#include<iostream>
#include<algorithm>
using namespace std;
//int yu[301],shu[301],ying[301],zong[301];
struct yers
{
string name;
int nian,yue,ri;
} a[110];
int main()
{
int n;
cin>>n;
for(int i=0;i<n;i++)
{
cin>>a[i].name >>a[i].nian >>a[i].yue >>a[i].ri ;
}
for(int i=0;i<n;i++)
{
if(a[i].nian >a[i+1].nian )
{
swap(a[i].name ,a[i+1].name );
}
if(a[i].nian ==a[i+1].nian )
{
if(a[i].yue >a[i+1].yue )
{
swap(a[i].name ,a[i+1].name );
}
if(a[i].yue ==a[i+1].yue )
{
if(a[i].ri >a[i+1].ri )
{
swap(a[i].name ,a[i+1].name );
}
}
}
}
for(int i=n-1;i>=0;i--)
{
cout<<a[i].name<<"\n" ;
}
}
by cjy2327134004 @ 2024-10-20 21:20:40
写错了,第36行
by zhzini6 @ 2024-10-20 21:22:06
建议你把比较放在函数里,这样不会乱
by zhanghaozhen @ 2024-10-20 22:07:24
@shunxinruyi 错了三处 1.你只交换结构体变量的名字不管他的年龄了 2.年月日越小年龄越大 3.注意,当学生年龄相等时后输入的应该先输出
by zhanghaozhen @ 2024-10-20 22:09:31
@shunxinruyi 看错了,年月日那个没错