Advertisement
kutuzzzov

Урок 3-2

Oct 4th, 2022
672
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.81 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <algorithm>
  5. #include <set>
  6.  
  7. using namespace std;
  8.  
  9. template<typename Container, typename Element>
  10. void FindAndPrint(Container container, Element element) {
  11.     auto element_pos = find(container.begin(), container.end(), element);
  12.     for (auto it = container.begin(); it != element_pos; ++it) {
  13.         cout << *it << " "s;
  14.     }
  15.     cout << endl;
  16.     for (auto it = element_pos; it != container.end(); ++it) {
  17.         cout << *it << " "s;
  18.     }
  19.     cout << endl;
  20. }
  21.  
  22. int main() {
  23.     set<int> test = { 1, 1, 1, 2, 3, 4, 5, 5 };
  24.     cout << "Test1"s << endl;
  25.     FindAndPrint(test, 3);
  26.     cout << "Test2"s << endl;
  27.     FindAndPrint(test, 0); // элемента 0 нет в контейнере
  28.     cout << "End of tests"s << endl;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement