Y75C @ 2024-02-20 11:34:52
#include <bits/stdc++.h>
using namespace std;
int m;
struct st{
string n;
int y,m,d,zb;
}t[114];
bool cmp(st a,st b){
if(a.y!=b.y) return a.y<b.y;
if(a.m!=b.m) return a.m<b.m;
if(a.d!=b.d) return a.d<b.d;
return a.zb>b.zb;
}
int main(){
scanf("%d",&m);
for(int i=0;i<m;i++){
cin>>t[i].n;
scanf("%d%d%d",&t[i].y,&t[i].m,&t[i].d);
}
sort(t,t+m,cmp);
for(int i=0;i<m-1;i++) cout<<t[i].n<<'\n';
cout<<t[m-1].n;
return 0;
}
by zhuowei @ 2024-02-22 15:16:43
@Y75C
你的zb没有赋值
改成这样就AC了
#include <bits/stdc++.h>
using namespace std;
int m;
struct st{
string n;
int y,m,d,zb;
}t[114];
bool cmp(st a,st b){
if(a.y!=b.y) return a.y<b.y;
if(a.m!=b.m) return a.m<b.m;
if(a.d!=b.d) return a.d<b.d;
return a.zb>b.zb;
}
int main(){
scanf("%d",&m);
for(int i=0;i<m;i++){
cin>>t[i].n;
scanf("%d%d%d",&t[i].y,&t[i].m,&t[i].d);
t[i].zb=i;
}
sort(t,t+m,cmp);
for(int i=0;i<m-1;i++) cout<<t[i].n<<'\n';
cout<<t[m-1].n;
return 0;
}