[Huawei machine trial] 67. parity in the seat, Huawei parity

Source: Internet
Author: User

[Huawei machine trial] 67. parity in the seat, Huawei parity

Question

Code

/* ------------------------------------- * Date: 2015-07-07 * Author: SJF0115 * Subject: parity seat * Source: huawei machine trial question ----------------------------------------- */# include <iostream> # include <string> # include <vector> # include <stack> # include <algorithm> using namespace std; vector <int> OddEvenSort (vector <int> num) {int I, j, k; int size = num. size (); vector <int> result; if (size = 0) {return result;} // if vector <int> odd; vector <int> Even; // parity separation for (I = 0; I <size; ++ I) {// odd if (num [I] % 2) {odd. push_back (num [I]);} // if // even else {even. push_back (num [I]);} // else} // for // sort (odd. begin (), odd. end (); sort (even. begin (), even. end (); // integrates int oddSize = odd. size (); int evenSize = even. size (); int number = 0; for (I = 0, j = 0, k = 1; I <oddSize | j <evenSize; ++ k) {// odd if (k % 2) {number = I <oddSize? Odd [I]: 0; ++ I;} // if // even else {number = j <evenSize? Even [j]: 0; ++ j;} // else result. push_back (number);} // while return result;} int main () {int n = 10; freopen ("C: \ Users \ Administrator \ Desktop \ acm.txt "," r ", stdin); vector <int> vec; int num, I; // enter for (I = 0; I <n; ++ I) {cin> num; vec. push_back (num);} // for // sort vector <int> result = OddEvenSort (vec); // output int size = result. size (); for (I = 0; I <size; ++ I) {if (I = size-1) {cout <result [I] <endl ;}// if else {cout <result [I] <"";} // else} // for return 0 ;}

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.