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

    {A} + {B}

    Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
    Total Submission(s): 7266    Accepted Submission(s): 2948

    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
     
    Author
    xhd
     
    Source
     
    Recommend
    lxj
     

    直接运用STL的set容器即可

    AC CODE:

     1 #include <iostream>
     2 #include <cstdio>
     3 #include <set>
     4 using namespace std;
     5 
     6 int main()
     7 {
     8     int n, m, i;
     9     set<int> S;
    10     set<int>::iterator it;
    11     while(scanf("%d%d", &n, &m) != EOF)
    12     {
    13         S.clear();
    14         n += m;
    15         while(n-- && scanf("%d", &i))  S.insert(i);
    16         it = S.begin();
    17         printf("%d", *it);
    18         for(it++; it != S.end(); it++)
    19             printf(" %d", *it);
    20         printf("\n");
    21     }
    22     return 0;
    23 }



  • 相关阅读:
    1058 A+B in Hogwarts (20)
    1046 Shortest Distance (20)
    1061 Dating (20)
    1041 Be Unique (20)
    1015 Reversible Primes (20)(20 分)
    pat 1027 Colors in Mars (20)
    PAT 1008 Elevator (20)
    操作系统 死锁
    Ajax的get方式传值 避免& 与= 号
    让IE浏览器支持CSS3表现
  • 原文地址:https://www.cnblogs.com/cszlg/p/2910483.html
Copyright © 2011-2022 走看看