总时间限制: 1000ms 内存限制: 65536kB描述
给定10个整数的序列,要求对其重新排序。排序要求:
1.奇数在前,偶数在后;
2.奇数按从大到小排序;
3.偶数按从小到大排序。
输入输入一行,包含10个整数,彼此以一个空格分开,每个整数的范围是大于等于0,小于等于100。输出按照要求排序后输出一行,包含排序后的10个整数,数与数之间以一个空格分开。样例输入
4 7 3 13 11 12 0 47 34 98
样例输出
47 13 11 7 3 0 4 12 34 98
来源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 }