用最简单无脑的写法,弄两个数组分别存
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 15;
int a[N], b[N];
int cnt1, cnt2;
int main()
{
int tmp;
for (int i = 0; i < 10; ++i)
{
cin >> tmp;
if (tmp % 2) //为奇
a[cnt1++] = tmp;
else
b[cnt2++] = tmp;
}
sort(a, a + cnt1, greater<int>());
sort(b, b + cnt2);
for (int i = 0; i < cnt1; ++i)
cout << a[i] << " ";
for (int i = 0; i < cnt2; ++i)
cout << b[i] << " ";
return 0;
}