dc_yangpengming @ 2024-12-08 18:39:02
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
struct node{
string s;
long long tot,sum;
};
node a[110];
bool cmp(node a,node b){
return a.tot<b.tot;
}
int main(){
int n,y,m,d;
cin>>n;
for(int i=1;i<=n;i++){
a[i].sum=i;
cin>>a[i].s>>y>>m>>d;
a[i].tot=y*10000+m*100+d;
}
sort(a+1,a+n+1,cmp);
for(int i=1;i<=n;i++){
cout<<a[i].s<<endl;
}
return 0;
}
by DDD_et @ 2024-12-08 18:44:14
@dc_yangpengming
请问年月为什么要乘 1000
和 100
啊,不是天数吗?
by dc_yangpengming @ 2024-12-08 18:48:33
@DDD_et 我想的是直接加起来判断,*是为了避免出现1992+1+1=1991+2+1类似情况
by tangweiren @ 2024-12-08 18:51:47
你先按年sort,一样的用月sort,再用天sort,反正这个n很小
by DDD_et @ 2024-12-08 18:52:29
@dc_yangpengming
你难道不是应该用一个差值(天数)判断吗?
by dc_yangpengming @ 2024-12-08 19:03:18
@DDD_et@tangweiren 已找到错误 没审清
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std;
struct node{
string s;
long long tot,sum;
};
node a[110];
bool cmp(node a,node b){
if(a.tot==b.tot) return a.sum>b.sum;
return a.tot<b.tot;
}
int main(){
int n,y,m,d;
cin>>n;
for(int i=1;i<=n;i++){
a[i].sum=i;
cin>>a[i].s>>y>>m>>d;
a[i].tot=y*10000+m*100+d;
}
sort(a+1,a+n+1,cmp);
for(int i=1;i<=n;i++){
cout<<a[i].s<<endl;
}
return 0;
}