码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 1412 {A} + {B}

时间:2017-05-28 14:27:59      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:rom   div   content   int   des   desc   stream   round   padding   

Problem 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
 
看到大神用STL,写的如此犀利。忍不住来一发。。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<limits.h>
#include<list>
using namespace std;

int main()
{
    int n,m,x;
    list<int>s1;
    list<int>s2;
    while(cin>>n>>m)
    {
        for(int i=0;i<n;i++)
        {
            cin>>x;
            s1.push_back(x);
        }
        for(int i=0;i<m;i++)
        {
            cin>>x;
            s2.push_back(x);
        }
        s1.merge(s2);
        s1.sort();
        s1.unique();
        int cnt=0;
        while(!s1.empty())
        {
           if(!cnt)
                cout<<s1.front();
           else
                cout<<" "<<s1.front();
           cnt=1;
           s1.pop_front();
        }
        cout<<endl;
    }
    return 0;
}


HDU 1412 {A} + {B}

标签:rom   div   content   int   des   desc   stream   round   padding   

原文地址:http://www.cnblogs.com/gccbuaa/p/6915582.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!