Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <set>
- using namespace std;
- int main() {
- /// set -- элементы без повторений
- /// быстро добавлять элемент -- O(log n) ||| n = 1000 logn примерно 7, n == 100000 около 20, 100000000 около 30
- /// быстро удалять O(log n)
- /// за O(1) (очень быстро) находить минимум в сете
- set<int> a;
- a.insert(5); //добавление элемента
- a.insert(3);
- a.insert(7);
- a.insert(3);
- for (auto e : a) { //выводим сет циклом
- cout << e << ' ';
- }
- cout << '\n';
- cout << *a.begin(); //берем первый элемент -- минимум
- cout << '\n';
- a.erase(3); //удаление элемента
- for (auto e : a) {
- cout << e << ' ';
- }
- cout << '\n';
- if (a.count(6)) {
- cout << "есть 6\n";
- }
- if (a.count(5)) {
- cout << "есть 5\n";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement