1 条题解

  • 0
    @ 2026-06-01 21:24:10
    #include <bits/stdc++.h>
    using namespace std;
    int main() 
    {
        ios::sync_with_stdio(false);
        cin.tie(NULL);
        int n, m;
        if (!(cin >> n)) return 0;
        vector<int> A(n);
        for (int i = 0; i < n; ++i)
            cin >> A[i];
        if (!(cin >> m)) return 0;
        vector<int> B(m);
        for (int i = 0; i < m; ++i)
            cin >> B[i];
        vector<int> unionSet;
        for (int x : A)
            unionSet.push_back(x);
        for (int x : B) 
        {
            bool found = false;
            for (int y : unionSet) 
            {
                if (x == y) 
                {
                    found = true;
                    break;
                }
            }
            if (!found)
                unionSet.push_back(x);
        }
        sort(unionSet.begin(), unionSet.end());
        unionSet.erase(unique(unionSet.begin(), unionSet.end()), unionSet.end());
        cout << "{";
        for (size_t i = 0; i < unionSet.size(); ++i) 
        {
            if (i > 0)
                cout << ",";
            cout << unionSet[i];
        }
        cout << "}" << endl;
        return 0;
    }
    

    看完点个赞

  • 1

信息

ID
1109
难度
9
分类
其他 点击显示
标签
递交数
1
已通过
1
通过率
100%
上传者