现在的位置: 首页 > 综合 > 正文

输入两个整型数组,返回一个数组:两个数组中的公共值。

2018年05月10日 ⁄ 综合 ⁄ 共 461字 ⁄ 字号 评论关闭
#include <stdio.h>
#include <queue>
#include <stack>
using namespace std;
vector<int>QT;
priority_queue<int,vector<int>,greater<int> >Q;
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	while (n--)
	{
		int x;
		scanf("%d",&x);
		Q.push(x);
	}
	while (QT.empty()==false)
	{
		QT.pop_back();
	}
	while (m--)
	{
		int x;
		scanf("%d",&x);
		while (x>=Q.top()&&Q.empty()==false)
		{
			if (x!=Q.top())
			{
				QT.push_back(Q.top());
			}
			else
				printf("%d ",x);
			Q.pop();
		}
		while (QT.empty()==false)
		{
			Q.push(QT.front());
			QT.pop_back();
		}
	}
	putchar('\n');
	return 0;
}

 

抱歉!评论已关闭.