2

#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;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值