zoukankan      html  css  js  c++  java
  • HDU1412:{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


     

    这次是用链表写的

    #include <stdio.h>
    #include <list>
    #include <string.h>
    using namespace std;
    
    int main()
    {
        int n,m,a[10005],b[10005],i,j;
        while(~scanf("%d%d",&n,&m))
        {
            for(i = 0; i<n; i++)
                scanf("%d",&a[i]);
            for(i = 0; i<m; i++)
                scanf("%d",&b[i]);
            list<int> la;
            list<int> lb;
            for(i = 0; i<n; i++)
            la.push_back(a[i]);
            for(i = 0; i<m; i++)
            lb.push_back(b[i]);
            la.merge(lb);
            la.sort();
            la.unique();
            int cnt = 0;
            while(!la.empty())
            {
                if(!cnt)
                printf("%d",la.front());
                else
                printf(" %d",la.front());
                cnt++;
                la.pop_front();
            }
            printf("
    ");
        }
    
        return 0;
    }
    


     

  • 相关阅读:
    第八章 多线程编程
    Linked List Cycle II
    Swap Nodes in Pairs
    Container With Most Water
    Best Time to Buy and Sell Stock III
    Best Time to Buy and Sell Stock II
    Linked List Cycle
    4Sum
    3Sum
    Integer to Roman
  • 原文地址:https://www.cnblogs.com/riskyer/p/3221510.html
Copyright © 2011-2022 走看看