原文链接:任意门
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;
}