题解
2023-08-21 10:40:26
发布于:广东
3阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<int> boy, girl;
for (int i = 0; i < n; i++) {
if (a[i] > 0) {
boy.push_back(a[i]);
} else {
girl.push_back(a[i]);
}
}
sort(boy.begin(), boy.end());
sort(girl.begin(), girl.end(), less<int>());
vector<int> result;
for (int i = 0; i < boy.size(); i++) {
result.push_back(boy[i]);
}
for (int i = 0; i < girl.size(); i++) {
result.push_back(girl[i]);
}
for (int i = 0; i < n; i++) {
cout << result[i] << " ";
}
cout << endl;
return 0;
}
这里空空如也
有帮助,赞一个