Advertisement
RobertDeMilo

YB4.8 Алгоритмы, возвращающие набор элементов

Nov 11th, 2023
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.10 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <set>
  5. #include <map>
  6.  
  7. using namespace std;
  8.  
  9. template<typename It>
  10. void PrintRange(It range_begin, It range_end)
  11. {
  12.     for (auto it = range_begin; it != range_end; ++it)
  13.     {
  14.         cout << *it << " ";
  15.     }
  16. }
  17.  
  18. int main()
  19. {
  20.     vector <string> langs = { "Python", "C++", "C", "Java", "C#" };
  21.  
  22.     auto it = partition(begin(langs), end(langs), [](const string& lang)
  23.         { return lang[0] == 'C'; });
  24.  
  25.     PrintRange(begin(langs), end(langs));
  26.     PrintRange(begin(langs), it);
  27.     //////////////////////////////////////////////////////////////////////////////////////
  28.     vector<string> c_langs(langs.size());
  29.  
  30.     auto it = copy_if(begin(langs), end(langs), begin(c_langs),
  31.         [](const string& lang)
  32.         { return lang[0] == 'C'; });
  33.  
  34.     PrintRange(begin(c_langs), it);
  35.     //////////////////////////////////////////////////////////////////////////////////////
  36.  
  37.     set<int> a = { 1,8,3 };
  38.     set<int> b = { 3,6,8 };
  39.     vector<int> v(a.size());
  40.  
  41.     auto it2 = set_intersection(begin(a), end(a), begin(b), end(b), begin(v));
  42.    
  43.     PrintRange(begin(v), it2);
  44.  
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement