Advertisement
sellmmaahh

tut12-zad3

Aug 2nd, 2015
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.87 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <stdexcept>
  4. #include <cmath>
  5. #include <set>
  6.  
  7.  
  8. using namespace std;
  9.  
  10. template<typename T>
  11. set<T> operator+ (const set<T> &s1, const set<T> &s2) {
  12. set<T> pom;
  13. for (auto x: s1) pom.insert(x);
  14. for (auto x: s2) pom.insert(x);
  15. return pom;
  16. }
  17.  
  18. template<typename T1>
  19. set<T1> operator*( const set<T1> &s1, const set<T1> &s2) {
  20.     set<T1> pom;
  21.     for (auto x: s1) {
  22.             for (auto y:s2) {
  23.                 if (x==y) pom.insert(x);
  24.             }}
  25.             return pom;
  26. }
  27. template<typename T2>
  28. ostream &operator<<(ostream &tok, const set<T2> s)
  29. { tok<<"{";
  30. auto it(s.begin());
  31. for (int i=0; i<s.size()-1; i++)
  32.         tok<<*it++<<",";
  33. tok<<*it<<"}";
  34. return tok;
  35. }
  36. int main() {
  37.   set<int> s1{3, 5, 1, 2, 8}, s2{7, 2, 8, 4};
  38. cout << s1 + s2 << std::endl;
  39. cout << s1 * s2 << std::endl;
  40.         return 0;
  41.  
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement