题解 | #整数奇偶排序#重写CMP函数
整数奇偶排序
https://www.nowcoder.com/practice/bbbbf26601b6402c9abfa88de5833163
#include <bits/stdc++.h> using namespace std; const int maxn = 1000 + 10; int arr[maxn]; bool cmp(int x,int y){ if(x % 2 == 1 && y % 2 == 1){ return y < x; }else if(x % 2 == 0 && y % 2 == 0){ return x < y; }else if(x % 2 == 1 && y % 2 == 0){ return true; }else{ return false; } } int main(){ while(cin >> arr[0]){ for(int i = 1;i < 10;i ++)cin >> arr[i]; sort(arr,arr + 10,cmp); for(int i = 0;i < 10;i ++)cout << arr[i] << " "; cout << endl; } return 0; }