morning_hope @ 2024-06-10 09:40:42
#include<bits/stdc++.h>
using namespace std;
struct xin{
string a;
int y,m,d;
int id;
}s[1000];
bool cmp(xin z,xin c){
if(z.y<c.y) return 1;
if(z.y>c.y) return 0;
if(z.y==c.y){
if(z.m<c.m) return 1;
if(z.m>c.m) return 0;
if(z.m==c.m){
if(z.d<c.m) return 1;
if(z.d>c.d) return 0;
if(z.d==c.d){
if(z.id>c.id) return 1;
else return 0;
}
}
}
}
int main(){
int n;
cin>>n;
for(int i=0;i<n;i++){
cin>>s[i].a>>s[i].y>>s[i].m>>s[i].d;
s[i].id=i;
}
sort(s,s+n,cmp);
for(int i=0;i<n;i++){
cout<<s[i].a<<endl;
}
return 0;
}
by morning_hope @ 2024-06-10 09:41:32
最后两个测试点没过
by xclh @ 2024-06-10 10:01:20
bool cmp(xin z,xin c){
if(z.y<c.y) return 1;
if(z.y>c.y) return 0;
if(z.y==c.y){
if(z.m<c.m) return 1;
if(z.m>c.m) return 0;
if(z.m==c.m){
if(z.d<c.m) return 1;
if(z.d>c.d) return 0;
if(z.d==c.d){
if(z.id>c.id) return 1;
else return 0;
}
}
}
}
检查 return
by morning_hope @ 2024-06-10 10:08:02
?
by morning_hope @ 2024-06-10 10:08:25
@xclh ??????
by xzy_caiji @ 2024-06-10 10:33:36
@morning_hope
if(z.d<c.m) return 1;
=>
if(z.d<c.d) return 1;
by morning_hope @ 2024-06-10 10:36:32
啊?哦~ 明白了
by morning_hope @ 2024-06-10 10:40:45
谢谢
by zenglicheng666 @ 2024-07-28 16:31:51
#include<bits/stdc++.h>
using namespace std;
struct stu{
string name;
int y,m,d,id;
}s[110];
int n;
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(){
cin>>n;
for(int i=1;i<=n;i++) {
cin>>s[i].name>>s[i].y>>s[i].m>>s[i].d;
s[i].id=i;
}
sort(s+1,s+n+1,cmp);
for(int i=1;i<=n;i++)
cout<<s[i].name<<endl;
return 0;
}