Advertisement
elephantsarecool

multiset

Jun 5th, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. #include<iostream>
  2. #include<set>
  3. #include<string>
  4. #include<algorithm>
  5. using namespace std;
  6. struct point
  7. {
  8.   int x;
  9.   int y;
  10.   point(int x,int y)
  11.   :x(x),y(y){}
  12.   int dist() const
  13.   {
  14.       return x*x+y*y;
  15.   }
  16. };
  17. struct cmp
  18. {
  19.     bool operator()(const point &x , const point &y)const
  20.     {
  21.         return x.dist() < y.dist();
  22.     }
  23. };
  24. ostream& operator<< (ostream &os, const point &pnt) {
  25.         return os<<pnt.x<<' '<<pnt.y<<endl;
  26. }
  27. int main()
  28. {
  29.   multiset<point,cmp> a;
  30.   while(1)
  31.   {
  32.     string command;
  33.     int x,y,r;
  34.     cin>>command;
  35.     if(command=="remove")
  36.     {
  37.       x=a.size();
  38.       cin>>r;
  39.       a.erase(point(0,r));
  40.       cout<<x-a.size()<<" points were removed"<<endl;
  41.     }
  42.     if(command=="print")
  43.     {
  44.       cin>>r;
  45.       for(auto it=a.equal_range(point(0,r)).first;it!=a.equal_range(point(0,r)).second;++it)
  46.       {
  47.         cout<<*it;
  48.       }
  49.     }
  50.     if(command=="add")
  51.     {
  52.       cin>>x>>y;
  53.       a.insert(point(x,y));
  54.     }
  55.   }
  56.   return 0;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement