题解 | #整数奇偶排序#重写CMP函数

整数奇偶排序

https://www.nowcoder.com/practice/bbbbf26601b6402c9abfa88de5833163

#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;
}

全部评论

相关推荐

04-27 08:59
常州大学 Java
牛客139242382号:《两门以上汇编语言》
点赞 评论 收藏
分享
05-30 12:03
山西大学 C++
offer来了我跪着接:不是骗子,等到测评那一步就知道为啥这么高工资了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务