06: integer parity sorting, 06 integer parity

Source: Internet
Author: User

06: integer parity sorting, 06 integer parity
06: integer parity sorting

  • View
  • Submit
  • Statistics
  • Question
Total time limit:
1000 ms
 
Memory limit:
65536kB
Description

A sequence of 10 integers must be reordered. Sorting requirements:

1. The odd number is in front and the even number is in the back;

2. The odd values are sorted in ascending order;

3. The even numbers are sorted in ascending order.

Input
Enter a row containing 10 integers separated by a space. The range of each integer is greater than or equal to 0 and less than or equal to 100.
Output
Output A line after sorting as required, containing the 10 integers after sorting. Separate the numbers with 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
Source
1873
 1 #include<iostream> 2 #include<algorithm> 3 #include<cstdio> 4 #include<cstring> 5 #include<cmath> 6 using namespace std; 7 int n,m; 8 int a[10001]; 9 int comp1(const int &a,const int &b)10 {11     if(a%2==1)12     return 1;13     else 14     return 0;15 }16 int comp2(const int &a,const int &b)17 {18     if(a%2==1)19     {20         if(a>b)21         return 1;22         else 23         return 0;24     }25     else 26     {27         if(a<b&&a%2==0&&b%2==0)28         return 1;29         else 30         return 0;31     }32 }33 int comp3(const int &a,const int &b)34 {35     if(a%2==1)36     return 1;37     else 38     return 0;39 }40 int main()41 {42     for(int i=1;i<=10;i++)43     cin>>a[i];44     sort(a+1,a+11,comp1);45     sort(a+1,a+11,comp2);46     for(int i=1;i<=10;i++)47     cout<<a[i]<<" ";48     return 0;49 }

 

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.