题干
c++实现
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<algorithm>
using namespace std;//compare函数不交换返回true
bool compare(int a, int b) {//1.a奇数,b偶数,不交换//2.a奇数,b奇数,a比b大,不交换//3.a偶数,b偶数,a比b小,不交换//4.其他情况,交换if (a % 2 == 1 && b % 2 != 1) {return true;}else if (a % 2 == 1 && b % 2 == 1 && a > b) {return true;}else if (a % 2 == 0 && b % 2 == 0 && a < b) {return true;}else {return false;}
}int main() {int arr[10];for (int i = 0; i < 10; i++){scanf("%d", &arr[i]);}sort(arr, arr + 10, compare);for (int i = 0; i < 10; i++){printf("%d ", arr[i]);}printf("\n");return 0;
}