Advertisement
maycod23

sets_multisets_practise

Apr 5th, 2022
1,008
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.78 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4.  
  5. int main()
  6. {
  7.     // 1.>basics of C++
  8.     // 2.>basics of for/while/do while loops
  9.     // 3.>basics of implementation/ arrays etc
  10.     // 4.>recursion
  11.     // 5.>binary search
  12.     // 6.>searching/sorting techniques
  13.     //stl techniques(vectors,maps,pairs)
  14.     //prefix sum (technique)
  15.  
  16.     // 7.>hashing
  17.     // 8.>two pointers
  18.     // 9.>stacks_queues
  19.  
  20.  
  21.     //lot of practise through contests and questions
  22.     // 10. > sets
  23.     // 11. > multisets
  24.     // 12. > questions
  25.     // 13. > sliding window technique
  26.     //questions of mixed variety of all the concepts studied till here
  27.  
  28.     // 14. > strings algorithms
  29.     // 15. > greedy algorithms
  30.     // 16. > bits manipulation
  31.  
  32.  
  33.     set<int> s;
  34.     s.insert(100); s.insert(1000);
  35.     s.insert(20); s.insert(2);
  36.     // cout << s.size() << endl;
  37.  
  38.     //iteration
  39.     // for (auto it = s.begin(); it != s.end(); it++)
  40.     // {
  41.     //  cout << *it << " " << endl;
  42.     // }
  43.     // cout << endl;
  44.     for (auto i : s)
  45.     {
  46.         cout << i << " " << endl;
  47.     }
  48.  
  49.     // cout << endl;
  50.  
  51.  
  52.     // cout << *(s.begin()) << endl;
  53.  
  54.  
  55.     //iteration and iterators and how to insert in set
  56.  
  57.  
  58.     //how to find or check an element in the set
  59.     int x; cin >> x;
  60.     if (s.find(x) == s.end())
  61.     {
  62.         cout << "NOT FOUND" << endl;
  63.     }
  64.     else cout << "FOUND" << endl;
  65.  
  66.  
  67.     //how to erase a element in the set
  68.  
  69.     s.erase(s.find(x));
  70.  
  71.     for (auto i : s)
  72.     {
  73.         cout << i << endl;
  74.     }
  75.  
  76.  
  77.     //////////////////////////////////////////////////////////////////////////////
  78.  
  79.  
  80.     // multiset<ll> m1; //store in ascending order
  81.  
  82.     // m1.insert(10); m1.insert(20); m1.insert(1); m1.insert(10);
  83.     // for (auto i : m1) cout << i << " "; cout << endl;
  84.  
  85.     // cout << m1.count(10) << endl;//frequency of 10
  86.  
  87.     // m1.erase(10);//erased all instances/occurences of 10
  88.     // for (auto i : m1) cout << i << " "; cout << endl;
  89.  
  90.     // m1.insert(10); m1.insert(10);
  91.     // for (auto i : m1) cout << i << " "; cout << endl;
  92.  
  93.     // m1.erase(m1.find(10));//erased only single instance of 10
  94.     // for (auto i : m1) cout << i << " "; cout << endl;
  95.  
  96.     // auto it1 = m1.begin();
  97.     // cout << *it1 << endl << endl << endl; //or*m1.begin()
  98. ///////////////////////////////////////////////////////////////////////////////////////
  99.  
  100.     multiset<ll, greater<ll>> m2; //store in descending order
  101.  
  102.     m2.insert(10); m2.insert(20); m2.insert(1); m2.insert(10);
  103.     for (auto i : m2) cout << i << " "; cout << endl;
  104.  
  105.     cout << m2.count(10) << endl;//ferqeuency of 10
  106.  
  107.     m2.erase(10);//erased all instances of 10
  108.     for (auto i : m2) cout << i << " "; cout << endl;
  109.  
  110.     m2.insert(10); m2.insert(10);
  111.     for (auto i : m2) cout << i << " "; cout << endl;
  112.  
  113.     m2.erase(m2.find(10));//erased only single instance of 10
  114.     for (auto i : m2) cout << i << " "; cout << endl;
  115.  
  116.     auto it2 = m2.begin();
  117.     cout << *it2 << endl;//or*m2.begin()
  118.  
  119.  
  120.     return 0;
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement