#include <iostream> #include <cstdio> #include <algorithm> using namespace std; const int NUM = 10; /** * 自定义排序规则 * 1.偶数在奇数前 * 2.偶数按大到小排序 * 3.奇数按小到大排序 * @return */ bool compare(int x, int y) { if ((x & 1) == 0 && (y & 1) == 0) { //x和y都是偶数,从小到大排序 return x < y; } else if ((x & 1) == 1 && (y & 1) == 1) { //x和y都是奇数,从大到小排序 return x > y; } else { //偶数排在奇数前 return (x & 1) > (y & 1); } } /** * 整数奇偶排序 * @return */ int main() { int numArr[NUM]; while (cin >> numArr[0]) { for (int i = 1; i < NUM; ++i) { cin >> numArr[i]; } sort(numArr, numArr + NUM, compare); for (int j = 0; j < NUM; ++j) { cout << numArr[j] << " "; } cout << endl; } return 0; }