#include #include class Set { private: const int FLAGS = 10e8; public: std::vector S; Set() { } Set& operator=(const Set& other) { this->S = other.S; return *this; } Set(const std::vector& vec) { std::vector flags(FLAGS, false); for (int i = 0; i < vec.size(); i++) { if (!flags[vec[i]]) { flags[vec[i]] = true; this->S.push_back(vec[i]); } } std::sort(this->S.begin(), this->S.end()); } Set Union(const Set& s) { std::vector flags(FLAGS, false); std::vector new_set; for (int i = 0; i < s.S.size(); i++) { if (!flags[s.S[i]]) { new_set.push_back(s.S[i]); flags[s.S[i]] = true; } } for (int i = 0; i < this->S.size(); i++) { if (!flags[this->S[i]]) { new_set.push_back(this->S[i]); flags[this->S[i]] = true; } } std::sort(new_set.begin(), new_set.end()); return { new_set }; } Set Intersection(const Set& s) { std::vector result; for (int i = 0; i < s.S.size(); i++) { if (std::find(this->S.begin(), this->S.end(), s.S[i]) != this->S.end()) { result.push_back(s.S[i]); } } return { result }; } Set Difference(const Set& s) { std::vector result; for (int i = 0; i < s.S.size(); i++) { if (std::find(this->S.begin(), this->S.end(), s.S[i]) == this->S.end()) { result.push_back(s.S[i]); } } return { result }; } Set SymmetricDifference(const Set& s) { std::vector result; for (int i = 0; i < s.S.size(); i++) { if (std::find(this->S.begin(), this->S.end(), s.S[i]) == this->S.end()) { result.push_back(s.S[i]); } } for (int i = 0; i < this->S.size(); i++) { if (std::find(s.S.begin(), s.S.end(), this->S[i]) == s.S.end()) { result.push_back(this->S[i]); } } return { result }; } void Add(int64_t element) { if (std::find(this->S.begin(), this->S.end(), element) == this->S.end()) { this->S.push_back(element); } } bool Contains(int64_t element) { for (int i = 0; i < this->S.size(); i++) { if (this->S[i] == element) { return true; } } return false; } void Remove(int64_t element) { for (int 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 temp : S) { std::cout << temp << " "; } std::cout << std::endl; } };