zoukankan      html  css  js  c++  java
  • HDU 1412 {A} + {B}

    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;
    }
    


  • 相关阅读:
    ElementUI Form 表单
    ElementUI 快速入门
    您即将提交的信息不安全
    pandas excel合并去重
    openpyxl刷新透视表
    安装kube-prometheus
    多个py文件生成一个可运行exe文件
    Locust关联和参数化
    使用Docker运行locust
    Python locust阶段压测
  • 原文地址:https://www.cnblogs.com/gccbuaa/p/6915582.html
Copyright © 2011-2022 走看看