#include<iostream>
#include<algorithm>
#define MAXSIZE 100
using namespace std;
bool cmp1(int a,int b){
return a<b;
}
bool cmp2(int a,int b){
return a>b;
}
int main(){
int data1[MAXSIZE]={0},data2[MAXSIZE]={0},n,i,tmp,count1=0,count2=0;
cin>>n;
for(i=0;i<n;i++){
cin>>tmp;
if(tmp%2==0){
data2[count2++]=tmp;
}else{
data1[count1++]=tmp;
}
}
sort(data1,data1+count1,cmp1);
sort(data2,data2+count2,cmp2);
if(count1>=count2){
for(i=0;i<count2;i++){
cout<<data1[i]<<" "<<data2[i]<<" ";
}
for(i=count2;i<count1;i++){
cout<<data1[i]<<" ";
}
}else{
for(i=0;i<count1;i++){
cout<<data1[i]<<" "<<data2[i]<<" ";
}
for(i=count1;i<count2;i++){
cout<<data2[i]<<" ";
}
}
return 0;
}
奇数、偶数交叉排序
最新推荐文章于 2020-12-25 14:03:09 发布