{A} + {B}

A - {A} + {B}
Time Limit:5000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Submit

Status
Description
給你兩個集合,要求{A} + {B}.
注:同一個集合中不會有兩個相同的元素.

Input
每組輸入數據分爲三行,第一行有兩個數字n,m(0<n,m<=10000),分別表示集合A和集合B的元素個數.後兩行分別表示集合A和集合B.每個元素爲不超出int範圍的整數,每個元素之間有一個空格隔開.

Output
針對每組數據輸出一行數據,表示合併後的集合,要求從小到大輸出,每個元素之間有一個空格隔開.

Sample Input
1 2
1
2 3
1 2
1
1 2

Sample Output
1 2 3

1 2

#include<cstdio>
#include<map>
using namespace std;
int main()
{
	int n, m;
	while (scanf("%d%d", &n, &m) != EOF)
	{
		map<int, int> mp;
		for (int i = 0; i < (m + n); i++)
		{
			int temp;
			scanf("%d", &temp);
			mp[temp]++;
		}
		map<int, int>::iterator b = mp.begin();
		map<int, int>::iterator e = mp.end();
		for (; b != e; )
		{
			printf("%d",b->first);
			++b;
			if (b == e)
				printf("\n");
			else
				printf(" ");
		}
	}
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章