cmp有点复杂
2024-08-21 09:55:00
发布于:云南
5阅读
0回复
0点赞
#include<bits/stdc++.h>
using namespace std;
struct node{
int xb,hei;
}a[10005];
bool cmp(node a,node b){
if(a.xb == b.xb && a.xb == 1) return a.hei < b.hei;
else if(a.xb == b.xb && b.xb == 0) return a.hei < b.hei;
else return a.xb < b.xb;
}
int main(){
int n; cin >> n;
for(int i = 1;i <= n;i++){
int t; cin >> t;
a[i].hei = t;
if(t < 0) a[i].xb = 1;
else a[i].xb = 0;
}
sort(a + 1,a + n + 1,cmp);
for(int i = 1;i <= n;i++){
cout << a[i].hei << " ";
}
return 0;
}
这里空空如也
有帮助,赞一个