文章

34

粉丝

9

获赞

5

访问

8.8k

头像
整数奇偶排序 题解:模板题
P1248 北京大学机试题
发布于2024年7月6日 21:35
阅读数 202

#include <bits/stdc++.h>

using namespace std;

const int maxn = 1000 + 10;
int arr[maxn];

bool cmp(int x,int y){
	if(x % 2 == 1 && y % 2 == 1){
		return y < x;
	}else if(x % 2 == 0 && y % 2 == 0){
		return x < y;
	}else if(x % 2 == 1 && y % 2 == 0){
		return true;
	}else{
		return false;
	}
}

int main(){
	while(cin >> arr[0]){
		for(int i = 1;i < 10;i ++)cin >> arr[i];
		
		sort(arr,arr + 10,cmp);
		
		for(int i = 0;i < 10;i ++)cout << arr[i] << " ";
		cout << endl;
	}	
	return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发