Advertisement
giGii

красиво выводит

Oct 8th, 2022
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.13 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <map>
  5. #include <set>
  6.  
  7. using namespace std;
  8.  
  9. template <typename It>
  10. void PrintRange(It range_begin, It range_end) {
  11.     if (range_begin != range_end) {
  12.         for (auto it = range_begin; it != range_end; ++it) {
  13.             cout << *it << " "s;
  14.         }
  15.  
  16.         cout << endl;
  17.     }
  18. }
  19.  
  20. template <typename С, typename P>
  21. void FindAndPrint(С container, P pivot) {
  22.     auto start = container.begin();
  23.     auto end = container.end();
  24.  
  25.     if (start != end && *start != pivot) {
  26.         for (auto element : container) {
  27.             if (element == pivot) {
  28.                 break;
  29.             }
  30.             cout << element << " "s;
  31.             ++start;
  32.         }
  33.  
  34.         cout << endl;
  35.        
  36.     }
  37.    
  38.     PrintRange(start, end);
  39. }
  40.  
  41. int main() {
  42.     set<int> test1 = {1, 1, 1, 2, 3, 4, 5, 5};
  43.     cout << "Test1.1"s << endl;
  44.     FindAndPrint(test1, 3);
  45.     cout << "Test1.2"s << endl;
  46.     FindAndPrint(test1, 0); // элемента 0 нет в контейнере
  47.     vector<int> test2 = {10, 9, 8};
  48.     cout << "Test2.1"s << endl;
  49.     FindAndPrint(test2, 9);
  50.     cout << "Test2.2"s << endl;
  51.     FindAndPrint(test2, 10);
  52.     cout << "Test2.3"s << endl;
  53.     FindAndPrint(test2, 8);
  54.     cout << "Test2.4"s << endl;
  55.     FindAndPrint(test2, 7);
  56.     string test3 = "abacabn";
  57.     cout << "Test3.1"s << endl;
  58.     FindAndPrint(test3, 'a');
  59.     cout << "Test3.2"s << endl;
  60.     FindAndPrint(test3, 'n');
  61.     cout << "Test3.3"s << endl;
  62.     FindAndPrint(test3, 'g');
  63.     vector<int> test4 = {}; // пустой контейнер
  64.     cout << "Test4.1"s << endl;
  65.     FindAndPrint(test4, 0);
  66.     cout << "Test4.2"s << endl;
  67.     FindAndPrint(test4, 1);
  68.     cout << "Test4.3"s << endl;
  69.     FindAndPrint(test4, 2);
  70.     vector<double> test5 = {10.1, 9.2, 8.3};
  71.     cout << "Test5.1"s << endl;
  72.     FindAndPrint(test5, 10.1);
  73.     cout << "Test5.2"s << endl;
  74.     FindAndPrint(test5, 9.2);
  75.     cout << "Test5.3"s << endl;
  76.     FindAndPrint(test5, 8.3);
  77.     cout << "Test5.4"s << endl;
  78.     FindAndPrint(test5, 12.1);
  79.     cout << "End of tests"s << endl;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement