Nine degrees OJ: Topic 1117: integer parity ordering

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.