zyc0611 @ 2024-07-11 19:42:08
哪位大佬帮忙修一下呀!!!
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
struct birth{
string s;
int y,m,d;
}k[1005];
bool cmp(birth a,birth b){
if(a.y==b.y){
if(a.m==b.m) return a.d<b.d;
else return a.m<b.m;
}
else return a.y<b.y;
}
int n;
signed main(){
cin>>n;
for(int i=0;i<n;i++) cin>>k[i].s>>k[i].y>>k[i].m>>k[i].d;
sort(k,k+n,cmp);
for(int i=0;i<n;i++) cout<<k[i].s<<"\n";
return 0;
}
by meifan666 @ 2024-07-11 19:47:56
@zyc0611 题中所给:如果有两个同学生日相同,输入靠后的同学先输出
结构体中加输入顺序
by meifan666 @ 2024-07-11 19:50:05
AC:
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
struct birth{
string s;
int y,m,d,l;
}k[1005];
bool cmp(birth a,birth b){
if(a.y==b.y){
if(a.m==b.m)
{
if(a.d==b.d)return a.l>b.l;
return a.d<b.d;
}
else return a.m<b.m;
}
else return a.y<b.y;
}
int n;
signed main(){
cin>>n;
for(int i=0;i<n;i++) {
cin>>k[i].s>>k[i].y>>k[i].m>>k[i].d;
k[i].l=i;
}
sort(k,k+n,cmp);
for(int i=0;i<n;i++) cout<<k[i].s<<"\n";
return 0;
}
求关
by NullPointerExpection @ 2024-07-11 19:53:03
如果有两个同学生日相同,输入靠后的同学先输出 @zyc0611
by OIer_Hhy @ 2024-07-11 19:55:35
@zyc0611
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
struct birth{
string s;
int y,m,d,id;
}k[1005];
bool cmp(birth a,birth 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;
}
else return a.m<b.m;
}
else return a.y<b.y;
}
int n;
signed main(){
cin>>n;
for(int i=0;i<n;i++) cin>>k[i].s>>k[i].y>>k[i].m>>k[i].d,k[i].id=i;
sort(k,k+n,cmp);
for(int i=0;i<n;i++) cout<<k[i].s<<"\n";
return 0;
}
by zyc0611 @ 2024-07-11 19:59:51
@NullPointerExpection 谢谢!
by zyc0611 @ 2024-07-11 20:00:17
@meifan666 谢谢!
by zyc0611 @ 2024-07-11 20:01:07
@OIer_Hhy 谢谢!