Hdu1412set实现集合合并

来源:互联网 发布:linux获取网卡ip地址 编辑:程序博客网 时间:2024/05/16 07:37
#include <stdlib.h>#include <string.h>#include <iostream>#include <set>using namespace std;set<int>a;set<int>::iterator it;int main(){    int i, j, k;    int n, m;        while (scanf("%d%d",&n,&m)!=EOF)    {a.clear();                for (i = 1; i <= n; i++)        {scanf("%d",&k);            a.insert(k);        }        for (i = 1; i <= m; i++)        {            scanf("%d",&k);             //if (a.find(k) == a.end())            //因为set是实现覆盖的不重复的,所以可以直接插入 a.insert(k);                    }        for (it = a.begin(), i = 1; it != a.end(); it++, i++)        {            if (i == a.size())            {printf("%d\n",*it);            }            else            {printf("%d ",*it);            }        }    }    return 0;}


原创粉丝点击