题解 | #整数奇偶排序#
整数奇偶排序
https://www.nowcoder.com/practice/bbbbf26601b6402c9abfa88de5833163
#include "cstdio" #include "iostream" #include "algorithm" using namespace std; bool comp(int lhd,int rhd) { if (lhd%2!=0&&rhd%2==0) { return true; } else if (lhd%2!=0&&rhd%2!=0&&lhd>rhd) { return true; }else if(lhd%2==0&&rhd%2==0&&lhd<rhd) { return true; } else { return false; } } int main() { int array[10]; while(scanf("%d %d %d %d %d %d %d %d %d %d",array,array+1,array+2,array+3,array+4,array+5,array+6,array+7,array+8,array+9)!=EOF) { sort(array,array+10,comp); for(int i=0;i<10;i++) { printf("%d ",array[i]); } printf("\n"); } }#考研复试#