nrk009

setSTL

Aug 2nd, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.20 KB | None | 0 0
  1.  
  2. #include<bits.stdc++.h>
  3. using namespace std;
  4. int main(){
  5.       set <int, > s;
  6.      /* set<char> myset{ 'A', 'B', 'C', 'D' };
  7.  
  8.       int a[]= {1, 2, 3, 4, 5, 5};
  9.     set<int> s2 (a, a + 6);  */
  10.  
  11.       for(int i=0;i<n;i++){
  12.       s.insert(a[i]);
  13.       }
  14.       set<int> iterator ::it;
  15.       for(it=s.begin();it!=s.end();it++)
  16.       cout<<*it;
  17.       for(auto it:s)
  18.       cout<<it;
  19.       for(auto it=s.begin();it!+s,end();it++)
  20.       cout<<*it<<" ";
  21.  
  22.      // set <int> gquiz2(gquiz1.begin(), gquiz1.end())
  23.  
  24.       //erase in set is same as other stl function ...
  25.     //  gquiz2.erase(gquiz2.begin(), gquiz2.find(30));
  26.  
  27.         s.erase (50); //erases the element 50;
  28.         s.erase(s.begin(),s.end()); //erases in a range
  29.             auto itr = my_multiset.find(value)
  30.         if(itr!=my_multiset.end()){
  31.             my_multiset.erase(itr);
  32.                 }
  33.  
  34.         //PAIR IN SETS
  35.           set<pair<int,int>>s;
  36.  
  37.           for(int i=0;i<n;i++){
  38.           cin>>x>>y;
  39.           s.insert({x,y});
  40.           }
  41.          set< pair<ll,ll> >::iterator it;
  42.  
  43.     for(it=s.begin(); it!=s.end(); ++it)
  44.     {
  45.         //first is x, y is the second element
  46.         cout<<it->first<<" "<<it->second<<endl;
  47.     }
  48.  
  49.     return 0;
  50. }
Add Comment
Please, Sign In to add comment