Problem1613end @ 2024-08-01 20:28:32
WA on #5#6
#include<bits/stdc++.h>
using namespace std;
int n;
struct loct{
string s;
int y,d,m,xh;
}a[1010];
bool cmp(loct at,loct bt){
if(at.y>bt.y) return 0;
else if(at.y==bt.y && at.m>bt.m) return 0;
else if(at.y==bt.y && at.m==bt.m && at.d>bt.d) return 0;
else if(at.y==bt.y && at.m==bt.m && at.d==bt.d && at.xh>bt.xh) return 0;
else return 1;
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i].s>>a[i].y>>a[i].m>>a[i].d;
a[i].xh=i;
}
stable_sort(a+1,a+n+1,cmp);
for(int i=1;i<=n;i++){
cout<<a[i].s<<endl;
}
return 0;
}
by haimingbei @ 2024-08-01 20:30:40
@Problem1613end
结构体会好排序一点
#include<bits/stdc++.h>
using namespace std;
struct stu{
string s;
int y,m,d,id;
};
stu a[105];
bool cmp(stu a,stu b){
if(a.y==b.y){
if(a.m==b.m){
if(a.d==b.d){
return a.id>b.id;
}
return a.d<b.d;
}
return a.m<b.m;
}
return a.y<b.y;
}
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i].s>>a[i].y>>a[i].m>>a[i].d;
a[i].id=i;
}
sort(a+1,a+n+1,cmp);
for(int i=1;i<=n;i++)cout<<a[i].s<<endl;
return 0;
}