题解 | #整数奇偶排序#
整数奇偶排序
https://www.nowcoder.com/practice/bbbbf26601b6402c9abfa88de5833163
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> #define len 1009 #define maxint 1<<31-1 int list[len]; int cmp1(const void*s1,const void*s2){ int a1 = *(int*)s1; int a2 = *(int*)s2; return a2-a1; } int cmp2(const void*s1,const void*s2){ int a1 = *(int*)s1; int a2 = *(int*)s2; return a1-a2; } int main(){ while(scanf("%d",&list[0])!=EOF){ for(int i = 1;i<10;i++){ scanf("%d",&list[i]); } qsort(list,10,sizeof(int),cmp1); int flag = 0; for(int i = 0;i<10;i++){ if(list[i]%2!=0){ if(flag){ printf(" "); } printf("%d",list[i]); flag = 1; } } qsort(list,10,sizeof(int),cmp2); for(int i = 0;i<10;i++){ if(list[i]%2==0){ if(flag){ printf(" "); } printf("%d",list[i]); flag = 1; } } printf("\n"); } }