#include #include class Set { public: Set() = default; explicit Set(const std::vector&); Set Union(const Set &) const; Set Intersection(const Set &) const; Set Difference(const Set &) const; Set SymmetricDifference(const Set &) const; void Add(int64_t); void Remove(int64_t); bool Contains(int64_t) const; std::vector Data() const; private: std::vector vector; }; Set::Set(const std::vector &vector) { for (auto const obj : vector) this->Add(obj); } Set Set::Union(const Set &old) const { Set new_set; for (auto const obj : old.Data()) new_set.Add(obj); for (auto const obj : this->vector) new_set.Add(obj); return new_set; } Set Set::Intersection(const Set &another) const { Set new_set; for (auto const obj1 : this->vector) for (auto const obj2 : another.Data()) if (obj1 == obj2) new_set.Add(obj1); return new_set; } Set Set::Difference(const Set &another) const { Set new_set; bool temp; for (auto const obj1 : this->vector) { temp = true; for (auto const obj2 : another.Data()) if (obj1 == obj2) { temp = false; break; } if (temp) new_set.Add(obj1); } return new_set; } Set Set::SymmetricDifference(const Set &another) const { return this->Difference(another).Union(another.Difference(*this)); } void Set::Add(int64_t num) { for (auto const obj : this->vector) if (obj == num) return; this->vector.push_back(num); } void Set::Remove(int64_t num) { for (unsigned int i = 0; i < this->vector.size(); i++) if (this->vector[i] == num) { this->vector.erase(this->vector.begin() + i); break; } } bool Set::Contains(int64_t num) const { for (auto const obj : this->vector) if (obj == num) return true; return false; } std::vector Set::Data() const { return this->vector; }