#include <iostream>
using namespace std;
/*
int main()
{
typedef int queue; queue a, b;
typedef int vector;vector v;
int i, x,n;
scanf("%d",&n);
for(i=0; i<n; i++)
{
cin >> x;
if(x%2==0) b.push(x);
//进入queue : 变量名.push(数据)
else a.push(x);
}
while(!a.empty()||!b.empty())//queue非空
{
if(!a.empty())
{
v.push_back(a.front());
a.pop();
}
if(!a.empty())
{
v.push_back(a.front());
a.pop();
}
if(!b.empty())
{
v.push_back(b.front());
b.pop();
}
}
cout << *v.begin();
//*v.begin()是指v.begin()指针指向的地址里的数据
for(auto i=v.begin()+1; i<v.end(); i++)
cout << " " << *i;
//i为指针 *i输出i指针指向地址里的数据
}
*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
queue<int> q1,q2;
int n;
cin>>n;
while(n--)
{
int m;
cin>>m;
if(m%2) q1.push(m);//进入奇数队列
else q2.push(m);//进入偶数队列
}
while(!q1.empty())//弹出奇数队列
{
int cnt=2,i=0;
while(cnt--&&!q1.empty()) {
if(i++) cout<<" ";
cout<<q1.front();
q1.pop();
}
if(!q2.empty()){
cout<<" "<<q2.front()<<" ";
q2.pop();
}
}
int i=0;
while(!q2.empty())//弹出多余的偶数队列
{
if(i++) cout<<" ";
cout<<q2.front();
q2.pop();
}
return 0;
}
2
最新推荐文章于 2024-04-23 16:15:02 发布