#include <bits/stdc++.h>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
void swap(int &a,int &b){
int t=a;a=b;b=t;
}
bool cmp(int a,int b){
if(a%2==1&&b%2==0) return 0;
if(a%2==0&&b%2==1) return 1;
if(a%2==1&&b%2==1) return a<b;
if(a%2==0&&b%2==0) return a>b;
}
int main(int argc, char** argv) {
int n,a[10];
n=10;
for(int i=0;i<n;i++)
cin>>a[i];
for(int i=0;i<n-1;i++)
for(int j=i+1;j<n;j++)
if(cmp(a[i],a[j])) swap(a[i],a[j]);
for(int i=0;i<n;i++)
cout<<a[i]<<" ";
cout<<endl;
return 0;
}
整数奇偶排序
最新推荐文章于 2024-07-15 13:32:43 发布