zhukexv @ 2024-03-31 19:17:58
#include <bits/stdc++.h>
using namespace std;
int n,b,c,e;
string a;
struct go{
string name;
int y,m,d;
} s[101];
bool cmp(go t,go t1){
if(t.y!=t1.y) return t.y<t1.y;
else{
if(t.m!=t1.m) return t.m<t1.m;
else return t.d<t1.d;
}
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a>>b>>c>>e;
s[n+1-i].name=a;
s[n+1-i].y=b;
s[n+1-i].m=c;
s[n+1-i].d=e;
}
sort(s+1,s+n+1,cmp);
for(int i=1;i<=n;i++){
cout<<s[i].name<<endl;
}
return 0;
}
by z_z_b_ @ 2024-03-31 19:23:27
@zhukexv
拿个id来记录输入顺序
#include <bits/stdc++.h>
using namespace std;
int n,b,c,e;
string a;
struct go{
string name;
int y,m,d,id;
} s[101];
bool cmp(go t,go t1){
if(t.y!=t1.y) return t.y<t1.y;
else{
if(t.m!=t1.m) return t.m<t1.m;
else
{
if(t.d!=t1.d) return t.d<t1.d;
return t.id>t1.id;
}
}
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a>>b>>c>>e;
s[n+1-i].name=a;
s[n+1-i].y=b;
s[n+1-i].m=c;
s[n+1-i].d=e;
s[n+1-i].id=i;
}
sort(s+1,s+n+1,cmp);
for(int i=1;i<=n;i++){
cout<<s[i].name<<endl;
}
return 0;
}
by zhukexv @ 2024-03-31 20:30:47
@z_zb 谢谢,已过