fxsnbfx @ 2024-08-09 18:31:59
#include<bits/stdc++.h>
using namespace std;
const int N=110;
struct student{
string s;
int y,m,d;
}stu[N];
bool cmp(struct student a,struct student b)
{
if(a.y!=b.y)
return a.y<b.y;
else
{
if(a.m!=b.m)
return a.m<b.m;
else
{
return a.d<b.d;
}
}
}
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>stu[i].s>>stu[i].y>>stu[i].m>>stu[i].d;
}
sort(stu+1,stu+1+n,cmp);
int l=1,r=0;
for(int i=1;i<n;i++)
{
if(stu[i].y==stu[i+1].y&&stu[i].m==stu[i+1].m&&stu[i].d==stu[i+1].d)
r+=1;
else
{
reverse(stu+l,stu+l+r);
l=i+1;
r=0;
}
}
for(int i=1;i<=n;i++)
{
cout<<stu[i].s<<endl;
}
return 0;
}
by Chenzhiqio0 @ 2024-08-13 09:02:26
用函数
by fxsnbfx @ 2024-08-13 20:43:05
@Chenzhiqio0 啥意思
by Machuanqi99 @ 2024-08-14 17:55:09
@fxsnbfx 额……我也不知,不过,我觉得你可以考虑不用这个函数,把所有条件判断包括交换位置写在cmp函数里
by fxsnbfx @ 2024-08-15 17:17:46
@Machuanqi99 但是reverse函数不是更方便嘛
by Machuanqi99 @ 2024-08-15 17:22:24
@fxsnbfx 好像有道理
by Machuanqi99 @ 2024-08-15 17:23:04
@fxsnbfx 我觉得你可以把它放到讨论区那块,再发问题
by Machuanqi99 @ 2024-08-15 17:23:50
@fxsnbfx 看到这个问题的人应该会多些
by fxsnbfx @ 2024-08-15 17:43:55
@Machuanqi99 啊?我发的不就是讨论区嘛
by fxsnbfx @ 2024-08-15 17:45:33
@Machuanqi99 哦哦,发到总版是吧
by Machuanqi99 @ 2024-08-15 18:27:19
@fxsnbfx 是的