2015 Beijing University software Engineering excellent undergraduate summer camp on the machine test---B: integer parity ordering

Source: Internet
Author: User

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

Related Article

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.