pukaijun20101021 @ 2023-07-07 22:20:21
#include<bits/stdc++.h>
using namespace std;
struct node{
string s;
int y;
int m;
int d;
int cs;
}b[105];
bool cmp(node a,node b){
if(a.y<b.y){
return 1;
}
if(a.y>b.y){
return 0;
}
if(a.y==b.y){
if(a.m<b.m){
return 1;
}
if(a.m>b.m){
return 0;
}
if(a.m==b.m){
if(a.d<b.d){
return 1;
}
if(a.d>b.d){
return 0;
}
if(a.d==b.d){
if(a.cs<b.cs){
return 1;
}
if(a.cs>b.cs){
return 0;
}
}
}
}
}
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>b[i].s>>b[i].y>>b[i].m>>b[i].d;
b[i].cs=i;
}
sort(b+1,b+1+n,cmp);
for(int i=1;i<=n;i++){
cout<<b[i].s<<endl;
}
return 0;
}
by wyl123ly @ 2023-07-21 14:48:12
你这个代码看起来有点麻烦
你可以吧月份和天数换算成年这样就方便很多了
然后最后一个测试点是因为有两个生日相同的人先输出编号较后面的(就是输入顺序)
#include<bits/stdc++.h>
using namespace std;
struct stu{
string name;
int yy;
int mm;
int dd;
double sum;
int bian;
}a[10005];
bool su(const stu &l,const stu &r){
if(l.sum!=r.sum){
return l.sum<r.sum;
}
if(l.sum==r.sum){
return l.sum>r.sum;
}
}
int main(){
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++){
cin>>a[i].name>>a[i].yy>>a[i].mm>>a[i].dd;
a[i].sum=1.0*a[i].yy+1.0*a[i].mm/12+a[i].dd*1.0/365;
a[i].bian=i;
}
sort(a+1,a+n+1,su);
for(int i=1;i<=n;i++){
if(a[i].sum==a[i+1].sum&&a[i].bian<a[i+1].bian){
string s;
s=a[i].name;
a[i].name=a[i+1].name;
a[i+1].name=s;
}
cout<<a[i].name<<endl;
}
return 0;
}
by wyl123ly @ 2023-07-21 14:49:22
@wyl123ly 哦对了顺便说一句这个是AC代码