View difference between Paste ID: VTqtCjn3 and y7XYpy4E
SHOW: | | - or go back to the newest paste.
1
/*
2
Заготовки кода здесь нет — вы легко справитесь без неё. А вот решение не забудьте сохранить — оно
3
вам понадобится в следующем задании.
4
*/
5
#include <algorithm>
6
#include <iostream>
7
#include <set>
8
#include <vector>
9
using namespace std;
10
/*void PrintRange(It range_begin, It range_end){
11
    bool first = true;
12
    auto i = range_begin;
13
    while(i!=range_end){
14
        if(first){
15
            cout<<*i;
16
            first=false;
17
        }else{
18
            cout<<" "<<*i;
19
        }
20
        ++i;
21
    }
22
    if(!first){
23
        cout<<endl;
24
    }
25
}*/
26
/*template <typename It>
27
void PrintRange(It range_begin, It range_end) {
28
    for (auto it = range_begin; it != range_end; ++it) {
29
        cout << *it << " "s;
30
    }
31
    cout << endl;
32
}*/
33
template <typename Container, typename Element>
34
void FindAndPrint(Container container, Element el) {
35
    auto find_el = find(begin(container), end(container), el);
36
    for (auto it = begin(container); it != find_el; ++it) {
37
        cout << *it << " "s;
38
    }
39
    cout << endl;
40
    for (auto it = find_el; it != end(container); ++it) {
41
        cout << *it << " "s;
42
    }
43
    cout << endl;
44
}
45
int main() {
46
    set<int> test = {1, 1, 1, 2, 3, 4, 5, 5};
47
    cout << "Test1"s << endl;
48
    FindAndPrint(test, 3);
49
    cout << "Test2"s << endl;
50
    FindAndPrint(test, 0); // элемента 0 нет в контейнере
51
    cout << "End of tests"s << endl;
52
}