文章

49

粉丝

49

获赞

8

访问

10.2k

头像
一个奇数堆,一个偶数堆
P1010 兰州大学2018/贵州大学2018年机试
发布于2024年3月17日 12:32
阅读数 377

#include<iostream>
#include<queue>
using namespace std;

bool even(int n)
{
	return !(n % 2);
}

int main()
{
	priority_queue<int, vector<int>, greater<int>> q1, q2;
	int n;
	cin >> n;
	int t;
	for (int i = 0; i < n; i++)
	{
		cin >> t;
		if (even(t))
		{
			q2.emplace(t);
		}
		else
		{
			q1.emplace(t);
		}
	}
	while (!q1.empty())
	{
		cout << q1.top() << " ";
		q1.pop();
	}
	while (!q2.empty())
	{
		cout << q2.top() << " ";
		q2.pop();
	}
	return 0;
}

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发