3 条题解

  • 0
    @ 2022-11-23 14:57:32
    #include <bits/stdc++.h>
    using namespace std;
    int n, m, x;
    signed main()
    {
        while (~scanf("%d%d", &n, &m))
        {
            vector<int> a, b;
            for (int i = 0; i < n; i++)
            {
                cin >> x;
                a.push_back(x);
            }
            for (int i = 0; i < m; i++)
            {
                cin >> x;
                b.push_back(x);
            }
            a.insert(a.end(), b.begin(), b.end());
            sort(a.begin(), a.end());
            a.erase(unique(a.begin(), a.end()), a.end());
            for (int i = 0; i < a.size(); i++)
                cout << a[i] << " ";
            puts("");
        }
        return 0;
    }
    
    • 0
      @ 2022-10-29 22:43:51
      #include<bits/stdc++.h>
      using namespace std;
      
      set<int > p;
      
      int main() {
          int n, m,x;
          cin >> n >> m;
          while(n--) {
              cin >> x;
              p.insert(x);
          }
          while(m--) {
              cin >> x;
              p.insert(x);
          }
          for(auto it = p.begin(); it != p.end(); it++) {
              cout << *it << " ";
          }
          // system("pause");
          return 0;
      }
      
      • 0
        @ 2022-5-21 13:35:35

        此题为集合合并题,我们可以试着用Python解答,开一个set(),然后每次把a和b中的元素add到set()里,最后转换成列表输出即可 代码如下:

        def getint():
            return list(map(int,input().split()))
        while True:
            try:
                n,m=getint()
                a=getint()
                b=getint()
                s=set()
                for i in a:
                    s.add(i)
                for i in b:
                    s.add(i)
                s=list(s)
                s.sort()
                print(*s)
            except:
                break
        
        • 1

        信息

        ID
        8
        时间
        1000ms
        内存
        256MiB
        难度
        5
        标签
        递交数
        38
        已通过
        17
        上传者