2856: 【例55.1】 整数奇偶排序

内存限制:64 MB 时间限制:1.000 S
评测方式:文本比较 命题人:
提交:4 解决:4

题目描述

现给了你一个 $10$ 个整数的序列,要求对其重新排序。排序要求:
奇数在前,偶数在后;
奇数按从大到小排序;
偶数按从小到大排序出。

输入

输入一行,包含 $10$ 个整数,彼此以一个空格分开,每个整数的范围是大于等于 $0$,小于等于$100$。

输出

按照要求排序后输出一行,包含排序后的 $10$ 个整数,数与数之间以一个空格分开。

样例输入 复制

4 7 3 13 11 12 0 47 34 98

样例输出 复制

47 13 11 7 3 0 4 12 34 98

提示

#include<bits/stdc++.h>
using namespace std;
int a[15],b[15],x,cnta,cntb;
int main(){
    for(int i=1;i<=10;i++){
        cin>>x;
        if(x%2) a[++cnta]=x;
        else b[++cntb]=x;
    }
    sort(a+1,a+cnta+1,greater<int>());
    sort(b+1,b+cntb+1);
    for(int i=1;i<=cnta;i++) cout<<a[i]<<' ';
    for(int i=1;i<=cntb;i++) cout<<b[i]<<' ';
    return 0;
}