#include class Set { public: explicit Set(const std::vector &input) { for (auto elem : input) _data.push_back(elem); } Set() {} Set Union(const Set &other) const { auto newSet = _data; const auto &otherData = other.Data(); auto otherSize = other.Data().size(); for (size_t i = 0; i < otherSize; ++i) { bool uniq = true; for (size_t j = 0; j < _data.size(); ++j) { if (_data[j] == otherData[i]) { uniq = false; break; } } if (uniq) newSet.push_back(otherData[i]); } return Set(newSet); } Set Intersection(const Set &other) const { const auto &thisData = _data; const auto &otherData = other._data; std::vector buf; for (auto elem : thisData) for (auto elemOther : otherData) { if (elem == elemOther) { buf.push_back(elem); break; } } return Set(buf); } Set Difference(const Set &other) const { const auto &thisData = this->Data().size() > other.Data().size() ? Data() : other.Data(); const auto &otherData = this->Data().size() < other.Data().size() ? Data() : other.Data(); auto size_other = otherData.size(); auto this_size = thisData.size(); bool notUniq = true; std::vector buf; for (size_t i = 0; i < this_size; i++) { notUniq = true; for (size_t j = 0; j < size_other; j++) { if (otherData[j] == thisData[i]) { notUniq = false; break; } } if (notUniq) buf.push_back(thisData[i]); } return Set(buf); } Set SymmetricDifference(const Set &other) const { auto this_set = Data(); auto other_set = other.Data(); auto size_other = other_set.size(); auto this_size = this_set.size(); std::vector new_v; for (size_t i = 0; i < this_size; i++) if (!other.Contains(this_set[i])) new_v.push_back(this_set[i]); for (size_t i = 0; i < size_other; i++) if (!Contains(other_set[i])) new_v.push_back(other_set[i]); return Set(new_v); } std::vector Data() const { return _data; } void Add(int64_t num) { bool uniq = true; for (auto elem : _data) if (elem == num) { uniq = false; break; } if (uniq) _data.push_back(num); } void Remove(int64_t num) { for (size_t i = 0; i < _data.size(); ++i) if (_data[i] == num) { _data.erase(_data.begin() + i); i -= 1; } } bool Contains(int64_t num) const { bool contains = false; for (auto elem : _data) if (elem == num) { contains = true; break; } return contains; } private: std::vector _data; };