daiyulong20120222 @ 2023-10-17 17:56:13
#include<bits/stdc++.h>
using namespace std;
struct node {
string name;
int yy,mm,dd;
}a[105];
bool cmp(node x,node y) {
if(x.yy!=y.yy) {
return x.yy<y.yy;
}
if(x.mm!=y.mm) {
return x.mm<y.mm;
}
if(x.dd!=y.dd) {
return x.dd<y.dd;
}
}
int main() {
int n;
cin>>n;
for(int i=1;i<=n;i++) {
cin>>a[i].name>>a[i].yy>>a[i].mm>>a[i].dd;
}
sort(a+1,a+n+1,cmp);
for(int i=1;i<=n;i++) {
cout<<a[i].name<<endl;
}
return 0;
}
by chenhanzheapple @ 2023-10-17 18:04:11
wyy
by sisi_ @ 2023-10-17 18:04:42
看不到你的评测记录啊,你是不是屏蔽了
是TLE的话有可能是因为sort不稳定,其他的不清楚
by lao_wang @ 2023-10-17 18:14:08
#include<bits/stdc++.h>
using namespace std ;
int n ;
struct node{
string name ;
int n , y , r , num ;
}a[123];
bool cmp(node a,node b){
if(a.n==b.n){
if(a.y==b.y){
if(a.r==b.r){
return a.num > b.num ;
}
return a.r<b.r ;
}
return a.y < b.y ;
}
return a.n < b.n ;
}
int main() {
// freopen("1.in","r",stdin);
// freopen("1.out","w",stdout) ;
cin >> n;
for(int i=0;i<n;i++){
cin >> a[i].name >> a[i].n >> a[i].y >> a[i].r ;
a[i].num = i ;
}
sort(a,a+n,cmp) ;
for(int i=0;i<n;i++){
cout << a[i].name << endl ;
}
return 0 ;
}
by daiyulong20120222 @ 2023-10-26 17:05:59
已经
#include<bits/stdc++.h>
using namespace std;
struct node {
string name;
int yy,mm,dd,id;
}a[105];
bool cmp(node x,node y) {
if(x.yy!=y.yy) {
return x.yy<y.yy;
}
if(x.mm!=y.mm) {
return x.mm<y.mm;
}
if(x.dd==y.dd&&x.mm==y.mm) {
return x.id>y.id;
}
if(x.dd!=y.dd&&x.mm==y.mm) {
return x.dd<y.dd;
}
}
int main() {
int n;
cin>>n;
for(int i=1;i<=n;i++) {
cin>>a[i].name>>a[i].yy>>a[i].mm>>a[i].dd;
a[i].id=i;
}
stable_sort(a+1,a+n+1,cmp);
for(int i=1;i<=n;i++) {
cout<<a[i].name<<endl;
}
return 0;
}