#include #include class Set { private: const int FlAG_SIZE = 10000000; public: std::vector s; Set() { } Set& operator=(const Set& other) { this->s = other.s; return *this; } Set(const std::vector& v) { std::vector flags(FlAG_SIZE, false); for (size_t i = 0; i < v.size(); ++i) { if (flags[v[i]] == false) { flags[v[i]] = true; this->s.push_back(v[i]); } } std::sort(this->s.begin(), this->s.end()); } Set Union(const Set& firstSet) { std::vector flags(FlAG_SIZE, false); std::vector newSet; for (size_t i = 0; i < firstSet.s.size(); ++i) { if (!flags[firstSet.s[i]]) { newSet.push_back(firstSet.s[i]); flags[firstSet.s[i]] = true; } } for (size_t i = 0; i < this->s.size(); ++i) { if (!flags[this->s[i]]) { newSet.push_back(this->s[i]); flags[this->s[i]] = true; } } std::sort(newSet.begin(), newSet.end()); return { newSet }; } Set Intersection(const Set& S) { std::vector res; for (size_t i = 0; i < S.s.size(); ++i) { if (std::find(this->s.begin(), this->s.end(), S.s[i]) != this->s.end()) { res.push_back(S.s[i]); } } return { res }; } Set Difference(const Set& firstSet) { std::vector res; for (size_t i = 0; i < firstSet.s.size(); ++i) { if (std::find(this->s.begin(), this->s.end(), firstSet.s[i]) != this->s.end()) { } else { res.push_back(firstSet.s[i]); } } return { res }; } Set SymmetricDifference(const Set& S) { std::vector res; for (size_t i = 0; i < S.s.size(); ++i) { if (std::find(this->s.begin(), this->s.end(), S.s[i]) != this->s.end()) { } else { res.push_back(S.s[i]); } } for (size_t i = 0; i < this->s.size(); ++i) { if (std::find(S.s.begin(), S.s.end(), this->s[i]) != S.s.end()) { } else { res.push_back(this->s[i]); } } return { res }; } void Add(int64_t element) { if (std::find(this->s.begin(), this->s.end(), element) != this->s.end()) { } else { this->s.push_back(element); } } bool Contains(int64_t element) { for (size_t i = 0; i < this->s.size(); ++i) { if (this->s[i] == element) { return true; } } return false; } void Remove(int64_t element) { for (size_t i = 0; i < this->s.size(); ++i) { if (this->s[i] == element) { this->s.erase(this->s.begin() + i); } } } std::vector Data() { return this->s; } void Print() { for (auto var : s) { std::cout << var << " "; } std::cout << std::endl; } };