Nine degrees OJ topic 1516: Adjust the array order so that the odd digits are preceded by even numbers

Source: Internet
Author: User

Topic 1516: Adjusting the array order so that the odd digits are preceded by even numbers

time limit:1 seconds

Memory limit:128 MB

Special question: No

submitted:3416

Resolution:1091

Title Description:

Enter an array of integers to implement a function that adjusts the order of the numbers in the array so that all the odd digits are placed in the first half of the array, all the even digits are located in the second half of the array, and the relative positions between the odd and odd, even and even, are guaranteed.

Input:

Each input file contains a set of test cases.
For each test case, enter an n for the first row, representing the number of digits in the array.
Enter n integers for the next line. Represents the number of n in an array.

Output:

corresponding to each test case,
Enter a row of n digits, representing the adjusted array. Note that the numbers and numbers are separated by a space, and there are no spaces after the last number.

Sample input:
51 2 3) 4 5
Sample output:
1 3 5) 2 4
1#include <cstdio>2#include <vector>3 using namespacestd;4 5 intMain () {6vector<int>V, V_even, v_odd;7     intN, temp, size, I;8      while(SCANF ("%d", &n)! =EOF) {9          for(i =0; I < n; i++) {Tenscanf"%d", &temp); One             if(Temp%2==1) A V_even.push_back (temp); -             Else - V_odd.push_back (temp); the         } -Size =v_even.size (); -         if(Size! =0) -printf"%d", v_even[0]); +          for(i =1; i < size; i++) -printf"%d", V_even[i]);  +Size =v_odd.size (); A          for(i =0; i < size; i++) atprintf"%d", V_odd[i]); -printf"\ n");  -     } -     return 0; -}

The simplest method is to use two containers to install them. Another way is to merge the sort, thinking about the same, in the merger is the first two arrays of the odd number first put in, and then put the even in.

Nine degrees OJ topic 1516: Adjust the array order so that the odd digits are preceded by even numbers

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.