lanbing_e @ 2024-07-22 10:59:05
#include<bits/stdc++.h>
using namespace std;
struct node{
string name;
int year,mouth,day;
};
int n;
node stu[101];
bool cmp(node x,node y)
{
if(x.year!=y.year) return x.year<y.year;
else if(x.mouth!=y.mouth) return x.mouth<y.mouth;
else return x.day<y.day;
}
int main()
{
cin>>n;
for(int i=0;i<n;i++)
{
cin>>stu[i].name>>stu[i].year>>stu[i].mouth>>stu[i].day;
}
sort(stu,stu+n,cmp);
for(int i=0;i<n;i++)
{
cout<<stu[i].name<<endl;
}
return 0;
}
最后一个WA了,咋做啊!
by pangpanghu @ 2024-07-22 14:39:54
P1104
by pangpanghu @ 2024-07-22 14:41:30
@lanbing_e
by lanbing_e @ 2024-07-23 08:29:44
@pangpanghu 好的
by zenglicheng666 @ 2024-07-28 16:31:08
#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;
}