-
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