文章

55

粉丝

57

获赞

11

访问

10.7k

头像
整数奇偶排序 题解:
P1248 北京大学机试题
发布于2024年3月14日 14:34
阅读数 154

#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;

bool cmp(int a,int b){
	if(a%2!=b%2){
        return a%2>b%2;
    }else{
        if(a%2==1){
            return a>b;
        }else{
            return a<b;
        }
    }

}

int main(){
	int a[11];
	while(cin>>a[0]>>a[1]>>a[2]>>a[3]>>a[4]>>a[5]>>a[6]>>a[7]>>a[8]>>a[9]){
		sort(a,a+10,cmp);
		for(int i = 0; i<10; i++){
			cout<<a[i]<<" ";
		}
        cout<<endl;
	}

}
 
登录查看完整内容


登录后发布评论

暂无评论,来抢沙发