Describe
Given a sequence of 10 integers, it is required to reorder it. Sorting requirements:
1. Odd in front, even in the rear;
2. Odd-numbered sort from large to small;
3. Even order from small to large.
Input
Enter a line that contains 10 integers separated by a single space, with each integer having a range greater than or equal to 0, and less than or equal to 100.
Output
after sorting according to the requirements, the output line contains 10 integers after sorting, separated by a space between the number and the number.
Sample input
4 7 3 13 11 12 0 47 34 98
Sample output
47 13 11 7 3 0 4 12 34 98
The problem is simple, you can use the array of data structure to solve, can also be solved with a chain list, the array is simple, directly on the code.
Code debugging for a long time, mainly subscript is always wrong, really drunk.
#include <iostream>using namespace Std;int jsz[10];int osz[10];int sz[10];int k=0,n=0;int i,j;int Main () {for (i=0 ; i<10; i++) {cin>>sz[i]; if (sz[i]%2==1) {jsz[k]=sz[i]; k++; } if (sz[i]%2==0) {osz[n]=sz[i]; n++; }} for (i=0, i<k; i++) {for (j=0; j<k-i; J + +) {if (jsz[j]<jsz[j+1]) {int t; T=JSZ[J]; JSZ[J]=JSZ[J+1]; jsz[j+1]=t; }}} for (i=0; i<n; i++) {for (j=0; j<n-1; J + +) {if (osz[j]>osz[j+1]) {int t; T=OSZ[J]; OSZ[J]=OSZ[J+1]; osz[j+1]=t; }}} for (i=0; i<k; i++) {cout<<jsz[i]<< ""; } for (i=0; i<n-1; i++) {cout<<osz[i]<< ""; } Cout<<osz[n-1]<<endl; return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
2015 Beijing University software Engineering excellent undergraduate summer camp on the machine test---B: integer parity ordering