Diary_51 @ 2024-05-19 18:35:20
#include<bits/stdc++.h>
using namespace std;
struct p
{
string name;
int n;
int y;
int r;
}a[105];
bool cmp(p x,p y)
{
if(x.n==y.n)
{
if(x.y==y.y)
{
return x.r<y.r;
}
return x.y<y.y;
}
return x.n<y.n;
}
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i].name>>a[i].n>>a[i].y>>a[i].r;
}
sort(a+1,a+n+1,cmp);
for(int i=1;i<=n;i++)
{
cout<<a[i].name<<endl;
}
return 0;
}
最后一个点不对,改好者可得一关
by MuLinnnnn @ 2024-05-19 18:39:58
(如果有两个同学生日相同,输入靠后的同学先输出)
by qw1234321 @ 2024-05-19 18:40:10
@Diary_51 这样:
#include<bits/stdc++.h>
using namespace std;
struct p
{
string name;
int n;
int y;
int r;
int id;
}a[105];
bool cmp(p x,p y)
{
if(x.n==y.n)
{
if(x.y==y.y)
{
if (x.r==y.r){
return x.id>y.id;
}
return x.r<y.r;
}
return x.y<y.y;
}
return x.n<y.n;
}
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i].name>>a[i].n>>a[i].y>>a[i].r;
a[i].id=i;
}
sort(a+1,a+n+1,cmp);
for(int i=1;i<=n;i++)
{
cout<<a[i].name<<endl;
}
return 0;
}
by MuLinnnnn @ 2024-05-19 18:40:20
记一下index,排序带上这题就结束了
by xiangzhenze611 @ 2024-05-19 18:43:28
@Diary_51
#include<bits/stdc++.h>
using namespace std;
struct p
{
string name;
int n;
int y;
int r;
int num;
}a[105];
bool cmp(p a,p b)
{
if(a.n!=b.n)
{
return a.n<b.n;
}
if(a.y!=b.y)
{
return a.y<b.y;
}
if(a.r!=b.r) return a.r<b.r;
return a.num>b.num;
}
int main()
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i].name>>a[i].n>>a[i].y>>a[i].r;
a[i].num=i;
}
sort(a+1,a+n+1,cmp);
for(int i=1;i<=n;i++)
{
cout<<a[i].name<<endl;
}
return 0;
}
by Diary_51 @ 2024-05-19 18:47:19
@xiangzhenze611 @Algophitronrhythm_ @Flying_hq 谢谢各位佬,以关注