Advertisement
Guest User

L12Y2005

a guest
May 23rd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <set>
  4. #include <algorithm>
  5. #include <iterator>
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.     set<int> number8;
  11.     set<int> number15;
  12.     set<int> number45;
  13.  
  14.     set<int> temp;
  15.  
  16.     for (int i = 30; i <= 150; i++) {
  17.         if (i % 8 == 0) {
  18.             number8.insert(i);
  19.         }
  20.         if (i % 15 == 0) {
  21.             number15.insert(i);
  22.         }
  23.         if (i % 45 == 0) {
  24.             number45.insert(i);
  25.         }
  26.     }
  27.  
  28.     set<int> association;
  29.     set<int> intersection;
  30.     set_intersection(number8.begin(), number8.end(), number15.begin(), number15.end(), inserter(temp, temp.begin()));
  31.     set_intersection(number45.begin(), number45.begin(), temp.begin(), temp.end(), inserter(intersection, intersection.begin()));
  32.  
  33.     temp.clear();
  34.  
  35.     set_union(number8.begin(), number8.end(), number15.begin(), number15.end(), inserter(temp, temp.begin()));
  36.     set_union(number45.begin(), number45.begin(), temp.begin(), temp.end(), inserter(association, association.begin()));
  37.  
  38.     cout << "Association: ";
  39.     copy(association.begin(), association.end(), ostream_iterator<int>(cout, " "));
  40.    
  41.     cout << "\nIntersection: ";
  42.     copy(intersection.begin(), intersection.end(), ostream_iterator<int>(cout, " "));
  43.     cout << "there is no number";
  44.  
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement