Topic 1117: integer parity ordering

Source: Internet
Author: User

Title Description:

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.

Input:

10 integers (0~100) of any sort, separated by a space.

Output:

There may be more than one set of test data, for each set of data, 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
Tips:

1. The test data may have many groups, please use a while (cin>>a[0]>>a[1]>>...>>a[9]) similar practice to achieve;
2. The input data is random and may be equal.



C + + code:

#include <stdio.h> #include <stdlib.h> int comp1 (const void *a,const void *b) {return * (int *) a-* (int *) b;} int C        OMP2 (const void *a,const void *b) {return * (int *) b-* (int *) A;} int main () {int a[10];                while (scanf ("%d", &a[0])!=eof) {int i,j=0,k=0,b[10],c[10];                for (i=1;i<10;i++) scanf ("%d", &a[i]);                        for (i=0;i<10;i++) {if (a[i]%2==0) {b[j]=a[i];j++;}                else {c[k]=a[i];k++;}                } qsort (b,j,sizeof (int), COMP1);                Qsort (c,k,sizeof (int), COMP2);                        for (i=0;i<k;i++) {if (i!=k-1) printf ("%d", c[i]);                else printf ("%d", c[i]);                } if (k!=0 && j!=0) printf ("");                        for (i=0;i<j;i++) {if (i!=j-1) printf ("%d", b[i]); ELSE printf ("%d", b[i]);        } printf ("\ n"); } return 0;} /************************************************************** problem:1117 User:carvin language:c++ Resul t:accepted time:50 Ms memory:1020 kb****************************************************************/



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.