http://codeforces.com/problemset/problem/1174/B
题目大意:
输入n,读入n个数字,对于所有相加得奇数的数交换位置,输出处理后字典序最小的序列
思路:输入时判定奇数和偶数是否齐全,若只有奇数或只有偶数,就没法进行处理,直接输出,若两者皆有,排序后输出
附代码
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int n;
int a[100005];
while(cin>>n)
{
int odd=0,even=0;
for(int i=0;i<n;i++)
{
cin>>a[i];
if(a[i]%2==0)even=1;
else odd=1;
}
//judge
if(odd==0||even==0)
{
//do nothing
}
else
{
sort(a,a+n);
}
//output
for(int i=0;i<n-1;i++)
{
cout<<a[i]<<" ";
}
cout<<a[n-1]<<endl;
}
}