Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <iomanip>
- #include <stdexcept>
- #include <cmath>
- #include <set>
- using namespace std;
- template<typename T>
- set<T> operator+ (const set<T> &s1, const set<T> &s2) {
- set<T> pom;
- for (auto x: s1) pom.insert(x);
- for (auto x: s2) pom.insert(x);
- return pom;
- }
- template<typename T1>
- set<T1> operator*( const set<T1> &s1, const set<T1> &s2) {
- set<T1> pom;
- for (auto x: s1) {
- for (auto y:s2) {
- if (x==y) pom.insert(x);
- }}
- return pom;
- }
- template<typename T2>
- ostream &operator<<(ostream &tok, const set<T2> s)
- { tok<<"{";
- auto it(s.begin());
- for (int i=0; i<s.size()-1; i++)
- tok<<*it++<<",";
- tok<<*it<<"}";
- return tok;
- }
- int main() {
- set<int> s1{3, 5, 1, 2, 8}, s2{7, 2, 8, 4};
- cout << s1 + s2 << std::endl;
- cout << s1 * s2 << std::endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement