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

找公共子集

2014年02月23日 ⁄ 综合 ⁄ 共 396字 ⁄ 字号 评论关闭
 
#include 
#include 

using namespace std;

int main()
{
	int m, n;
	vector a, b;
	int x, y;

	cin >> m >> n;// get the num of the two arrays

	// init the array
	for (int i = 0; i < m; i++) {
		int t;
		cin >> t;
		a.push_back(t);
	}

	for (int i = 0; i < n; i++) {
		int t;
		cin >> t;
		b.push_back(t);
	}

	vector t;
	x = y = 0;

	while (x < b.size() || y < a.size()) {
		while (x < a.size() && a[x] < b[y]) x++;
		while (y < b.size() && b[y] < a[x]) y++;
		t.push_back(a[x]);
	}

	for (int i = 0; i < t.size(); i++)
		cout << "/t" << t[i];
	cout << endl;
}


【上篇】
【下篇】

抱歉!评论已关闭.