#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int n, m;
cin >> n;
int origin[1001], lower[1001], upper[1001];
int i, j = 0, k = 0;
for (i = 0; i < n; i++)
cin >> origin[i];
cin >> m;
for (i = 0; i < n; i++)
{
if (origin[i] < m)
{
lower[j] = origin[i];
j++;
}
else
{
upper[k] = origin[i];
k++;
}
}
if (k == 0)
{
for (i = 0; i < j - 1; i++)
cout << lower[i] << " ";
cout << lower[j - 1] << endl << endl;
}
else
{
for (i = 0; i < j; i++)
cout << lower[i] << " ";
for (i = 0; i < k - 1; i++)
cout << upper[i] << " ";
cout << upper[k - 1] << endl;
sort(upper, upper + k);
for (i = 0; i < k - 1; i++)
cout << upper[i] << " ";
cout << upper[k - 1] << endl;
}
return 0;
}
《NOJ1030 马拉松竞赛》有1个想法