Facebook
From Soiled Mockingjay, 5 Years ago, written in C++.
Embed
Download Paste or View Raw
Hits: 200
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. class point{
  6.     float a, b;
  7. public:
  8.     point(){
  9.         this->a=0;
  10.         this->b=0;
  11.     }
  12.     point(float a, float b){
  13.         this->a=a;
  14.         this->b=b;
  15.     }
  16.  
  17.     float getA() const
  18.     {
  19.         return this->a;
  20.     }
  21.     float getB() const
  22.     {
  23.         return this->b;
  24.     }
  25. };
  26.  
  27. vector<point> f(const vector<point> &vec, const point &a, const point &b)
  28. {
  29.     vector<point> vec2;
  30.     for(const point &p : vec)
  31.         {
  32.             if(p.getA()>=a.getA() && p.getA() <=b.getA() && p.getB()>=b.getB() && p.getB() <= a.getB())
  33.             {
  34.                 vec2.push_back(p);
  35.             }
  36.         }
  37.     return vec2;
  38. }
  39.  
  40. int main()
  41. {
  42.     vector<point> vec(10);
  43.     for(int i=0; i<10; i++)
  44.     {
  45.         vec[i]=point(i,i);
  46.     }
  47.  
  48.     point a(2,6);
  49.     point b(5,3);
  50.  
  51.     vector<point> p = f(vec, point(2,6), point(5,3));
  52.     for(const point &pp : p)
  53.     {
  54.         cout<<pp.getA()<<' '<<pp.getB()<<endl;
  55.     }
  56.     return 0;
  57. }
  58.