#include #include #include #include #include using std::string; using std::cout; using std::cin; using std::vector; using std::endl; class Set { public: explicit Set(const vector &vector) { for (auto x : vector) { this->Add(x); } } Set() { } Set Union(const Set &other) const { std::vector tmp; tmp.insert(tmp.end(), this->vec.begin(), this->vec.end()); tmp.insert(tmp.end(), other.vec.begin(), other.vec.end()); return Set(tmp); } Set Intersection(const Set &other) const { Set new_set; bool used = false; for (auto x : this->vec) { for (auto y : other.vec) { if (x == y) { new_set.vec.push_back(x); used = true; } } if (used) break; } return new_set; } Set Difference(const Set &other) const { Set new_set; bool used; for (auto x : this->vec) { used = false; for (auto y : other.vec) { if (x == y) { used = true; break; } } if (!used) { new_set.vec.push_back(x); } } return new_set; } Set SymmetricDifference(const Set &other) const { Set new_set1 = this->Difference(other); Set new_set2 = other.Difference(*this); return new_set1.Union(new_set2); } void Add(int64_t num) { for (auto x : this->vec) { if (x == num) { return; } } this->vec.push_back(num); } void Remove(int64_t num) { auto it = std::find(this->vec.begin(), this->vec.end(), num); if (it != this->vec.end()) this->vec.erase(it); } bool Contains(int64_t num) const { for (auto x : this->vec) { if (x == num) return true; } return false; } vector Data() const { return this->vec; } vector vec; };