hyh0174 @ 2023-12-01 21:48:03
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
struct stu
{
string s;
int y,m,d,o;
}sb[110];
bool cmp(stu a,stu b)
{
if(a.y!=b.y)
return a.y<b.y?true:false;
else if(a.m!=b.m)
return a.m<b.m?true:false;
else if(a.d!=b.d)
return a.d<b.d?true:false;
else
return a.o>b.o?true:false;
}
int main()
{
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%s %d %d %d",&sb[i].s,&sb[i].y,&sb[i].m,&sb[i].d);
sb[i].o=i+1;
}
stable_sort(sb,sb+n,cmp);
for(int i=0;i<n;i++)
printf("%s\n",sb[i].s);
return 0;
}
by hispy @ 2023-12-04 21:27:30
@hyh0174 string不能直接用scanf,printf
#include<cstdio>
#include<algorithm>
#include<string>
#include<iostream>
using namespace std;
struct stu
{
string s;
int y,m,d,o;
}sb[110];
bool cmp(stu a,stu b)
{
if(a.y!=b.y)
return a.y<b.y?true:false;
else if(a.m!=b.m)
return a.m<b.m?true:false;
else if(a.d!=b.d)
return a.d<b.d?true:false;
else
return a.o>b.o?true:false;
}
int main()
{
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
cin>>sb[i].s;
scanf("%d %d %d",&sb[i].y,&sb[i].m,&sb[i].d);
sb[i].o=i+1;
}
stable_sort(sb,sb+n,cmp);
for(int i=0;i<n;i++)
cout<<sb[i].s<<endl;
//or printf("%s\n",sb[i].s.c_str());
return 0;
}
这样就A了
by hyh0174 @ 2023-12-04 21:28:28
@hispy 好好好