1#include <stdio.h>2#include <algorithm>3 using namespacestd;4 Const intn=Ten;5 intMain ()6 {7 intarr[Ten],odd[Ten],even[Ten];8 while(SCANF ("%d", &arr[0])!=EOF)9 {Ten for(intI=1; I<n; ++i) Onescanf"%d",&arr[i]); ASort (arr,arr+N); - intio=0, ie=0; - for(intI=0; I<n; ++i) the if(arr[i]%2==0) -even[ie++]=Arr[i]; - Else -odd[io++]=Arr[i]; + BOOLmark=0;//Mark There is no odd - if(io!=0) +mark=1; A while(io!=0)//print odd from backward forward at { -printf"%d", odd[--io]); - if(io!=0) -printf" "); - } - intCnt=0; in while(Cnt!=ie)//print an even number from front to back - { to if(0==cnt &&0==mark)//"Caution" is not preceded by an odd number and cannot be preceded by a space +printf"%d", even[cnt++]); -printf"%d", even[cnt++]); the } *printf"\ n"); $ }Panax Notoginseng return 0; -}
Because the data may be organic, only odd, only an even number, to be discussed in different situations, the processing of whitespace is very important
Nine degrees OJ: Topic 1117: integer parity ordering