#include<fstream>
#include<algorithm>
#include<iostream>
using namespace std;
#define maxn 1010
int vec[maxn];
int odd_vec[maxn];
int even_vec[maxn];
bool cmp(int a,int b)
{
return a>b;
}
int main()
{
ifstream in("C-large-practice.in");
ofstream out("cs.out");
int T,N,tmp;
in >> T;
for(int i = 0;i<T;i++)
{
in >> N;
int cnt_odd = 0,cnt_even = 0;
for(int j = 0;j<N;j++)
{
in>> tmp;
if(tmp %2 == 0){
even_vec[cnt_even++] = tmp;
vec[j] = 0;
}else{
odd_vec[cnt_odd++] = tmp;
vec[j] = 1;
}
}
/* cout<<"排序前的偶数序列:"<<endl;
for(int k =0;k<cnt_even;k++)
cout<<even_vec[k]<<" ";
cout<<endl;*/
sort(even_vec,even_vec+cnt_even,cmp);
/* cout<<"排序后的偶数序列:"<<endl;
for(int k =0;k<cnt_even;k++)
cout<<even_vec[k]<<" ";
cout<<endl;*/
/*cout<<"排序前的奇数序列:"<<endl;
for(int k =0;k<cnt_odd;k++)
cout<<odd_vec[k]<<" ";
cout<<endl;*/
sort(odd_vec,odd_vec+cnt_odd);
/* cout<<"排序后的奇数序列:"<<endl;
for(int k =0;k<cnt_odd;k++)
cout<<odd_vec[k]<<" ";
cout<<endl;*/
int e = 0,o = 0;
/*
for(int j = 0;j<N;j++)
{
if(vec[j] == 0){
vec[j] = even_vec[e++];
}else{
vec[j] = odd_vec[o++];
}
}*/
out<<"Case #"<<i+1<<":";
for(int j = 0;j<N;j++)
{
if(vec[j] == 0){
out<<" "<<even_vec[e++];
}else{
out<<" "<<odd_vec[o++];
}
}
out<<endl;
}
return 0;
}
GoogeJam_Sorting
最新推荐文章于 2024-11-12 21:20:18 发布