点击查看代码
#include<iostream>
#include<algorithm>
using namespace std;
int cmp_single(int a, int b)
{
return a > b;
}
int cmp_double(int a, int b)
{
return a < b;
}
int main()
{
int a[10];
int single[10];
int doub[10];
int sin = 0, dou = 0;
for (int i = 0; i < 10; i++)
{
cin >> a[i];
if (a[i] % 2 != 0)
{
sin++;
single[sin] = a[i];
}
else
{
dou++;
doub[dou] = a[i];
}
}
sort(single + 1, single + sin + 1, cmp_single);
sort(doub + 1, doub + dou + 1, cmp_double);
for (int i = 1; i <= sin; i++)
{
cout << single[i] << " ";
}
for (int i = 1; i <= dou; i++)
{
cout << doub[i] << " ";
}
cout << endl;
return 0;
}