Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
8163 admin 集合运算 C++ 通过 100 3 MS 280 KB 967 2025-03-26 20:12:54

Tests(10/10):


#include <bits/stdc++.h> using namespace std; int m,n,l; int main(){ vector<int> a; vector<int> b; vector<int> c; cin>>n; for (int i = 0;i<n;i++){ cin>>l; a.push_back(l); } cin>>m; for (int i = 0;i<m;i++){ cin>>l; b.push_back(l); } sort(a.begin(),a.end()); sort(b.begin(),b.end()); set_intersection(a.begin(), a.end(), b.begin(), b.end(), back_inserter(c));//交集 for(vector<int>::iterator it = c.begin(); it != c.end();it ++) cout << *it << " "; cout<<endl; c.clear(); set_union(a.begin(), a.end(), b.begin(), b.end(), back_inserter(c));//并集 for(vector<int>::iterator it = c.begin(); it != c.end();it ++) cout << *it << " "; cout<<endl; c.clear(); set_difference(a.begin(), a.end(), b.begin(), b.end(), back_inserter(c)); //差集(b中属于a的元素去掉) for(vector<int>::iterator it = c.begin(); it != c.end();it ++) cout << *it << " "; cout<<endl; c.clear(); }


测评信息: