自己看题解
2025-02-12 13:39:26
发布于:江苏
2阅读
0回复
0点赞
其实会结构体排序的搞清楚true or false就行awa(不会有人搞不清吧)
#include<iostream>
#include<algorithm>
using namespace std;
struct people
{
int number,money,office,level;
}a[1005];
bool cmp(const people& x,const people y)
{
if(x.money>y.money)
{
return 1;
}
else if(x.money<y.money)
{
return 0;
}
else
{
if(x.level>y.level)
{
return 1;
}
else if(x.level<y.level)
{
return 0;
}
else
{
if(x.office>y.office)
{
return 0;
}
else if(x.office<y.office)
{
return 1;
}
else
{
if(x.number>y.number)
{
return 0;
}
else if(x.number<y.number)
{
return 1;
}
}
}
}
}
int n;
int main(){
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i].number>>a[i].money>>a[i].office>>a[i].level;
}
sort(a+1,a+1+n,cmp);
for(int i=1;i<=n;i++)
{
cout<<a[i].number<<" ";
}
}
这里空空如也
有帮助,赞一个