Introduction to openjudge-Computing (A)-integer parity ordering

Source: Internet
Author: User

Describe:

Enter 10 integers separated by a space
After reordering output (also separated by spaces), ask:
1. First output the odd number, and according to the order from large to small;
2. Then output the even numbers and sort them from small to large. Enter any sort of 10 integers (0~100), each with a space-delimited output sorted by the required output, separated by a space sample input

4 7 3 13 11 12 0 47 34 98

Sample output

47 13 11 7 3 0 4 12 34 98

Tip 1. The test data may have many groups, use a while (cin>>a[0]>>a[1]>>...>>a[9]) similar to the implementation;

2. The input data is random and may be equal.

Idea: This problem is a bit difficult , pay special attention to only the odd number of cases without even, only an even number is not an odd number of cases. There may not be even, so don't have any spaces after the odd output!

The code is as follows:

1 /********************************* 2 * Date: 2013-2-53 * SJF01154 * Title number: Nine degrees OJ topic 1117: integer parity ordering5 * Source:http://ac.jobdu.com/problem.php?pid=11176 * Result: AC7 * Source: 2008 Beijing University Graphic Laboratory computer Research the real problem8 * Summary: Note that only odd numbers do not have even numbers, and only an even number is not an odd number case. There may not be even, so don't have any spaces after the odd output! 9 **********************************/ Ten#include <stdio.h> One#include <stdlib.h> A#include <string.h> - //even sort - intcmpConst void*a,Const void*b) { the     return*(int*) A-* (int*) b; - } - //Odd Sort - intCMP2 (Const void*a,Const void*b) { +     return*(int*) B-* (int*) A; - } + intMain () A { at     intN,i,evencount,oddcount; -     intnumber[Ten]; -     inteven[Ten]; -     intodd[Ten]; -     //freopen ("C:\\users\\sjf\\desktop\\acm.txt", "R", stdin); -      while(SCANF ("%d", &number[0])!=EOF) in     { -Evencount =0; toOddcount =0; +         if(number[0] %2){ -odd[oddcount++] = number[0]; the         } *         Else{ $even[evencount++] = number[0];Panax Notoginseng         } -          for(i =1; I <Ten; i++){ thescanf"%d",&number[i]); +             //Odd A             if(Number[i]%2){ theodd[oddcount++] =Number[i]; +             } -             //even $             Else{ $even[evencount++] =Number[i]; -             } -         } the         //Sort -Qsort (Even,evencount,sizeof(even[0]), CMP);WuyiQsort (Odd,oddcount,sizeof(odd[0]), CMP2); the         //1. First output the odd number, and according to the order from large to small, 2. Then output the even number, and arranged from small to large.  -         //output Odd Wu         intFlag =0; -          for(i =0; I < oddcount;i++){ About             if(flag) { $printf" "); -             } -printf"%d", Odd[i]); -Flag =1; A         } +         //No even number, only odd . the         if(Evencount = =0){ -printf"\ n"); $         } the         //There are even no odd numbers the         Else if(Oddcount! =0){ theprintf" "); the         } -         //Output Even in          for(i =0; I < evencount;i++){ the             if(i = = evencount-1){ theprintf"%d\n", Even[i]); About             } the             Else{ theprintf"%d", Even[i]); the             } +         } -     } the     return 0;Bayi}

Introduction to openjudge-Computing (A)-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.