Codeforces Round #563 (Div. 2)B;Ehab Is an Odd Person

原文链接:任意门
Input
The first line contains an integer n (1≤n≤10^5) — the number of elements in the array a。
The second line contains n space-separated integers a1, a2, …, an (1≤ai≤10^9) — the elements of the array a.
Output
The only line contains n space-separated integers, the lexicographically smallest array you can obtain.
Examples:
input
3
4 1 7
output
1 4 7
input
2
1 1
output
1 1
题目大意:给你一组数,让你交换两个数的位置,让它们的和为奇数,且使其交换后,顺序满足最小字典序列。
思路:这就是一道狗题,看代码,你就会******了,只需要sort排序。
代码

#include"iostream"
#include"algorithm"
#include"cstdio"
#include"cstring"	
long long a[10000006],n,js=0,os=0;
using namespace std;
int main(){
	std::ios::sync_with_stdio(false);
	cin>>n;
	for(int i=0;i<n;i++) {
		cin>>a[i];
		if(a[i]%2!=0) js++;
		else{
			os++;
		}
	}
	if(js!=0&&os!=0) sort(a,a+n);
	for(int i=0;i<n;i++){
		cout<<a[i];
	if(i!=n-1){
	    cout<<" ";
	  }
     }
     return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值