1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
#include <iostream>
#include <list>
using namespace std;
struct PT{ int x, y; };
using LIST = list<PT>;
//==========================================================
ostream & operator << ( ostream &out, const LIST &L ){ for ( auto e : L ) cout << e.x << " " << e.y << '\n'; return out; }
//==========================================================
void split( const LIST &input, LIST &above, LIST &below, int m, int q )
{
above.clear(); below.clear();
for ( auto e : input )
{
if ( e.y < m * e.x + q ) below.push_back( e );
else above.push_back( e );
}
}
//==========================================================
int main()
{
int m = 1, q = 1;
LIST L{ {0,0}, {1,1}, {-1,1}, {-2,1}, {-3,1} };
cout << "Original:\n" << L;
cout << "\nDividing line is y = " << m << " x + " << q << '\n';
LIST above, below;
split( L, above, below, m, q );
cout << "\nAbove (or on):\n" << above;
cout << "\nBelow: \n" << below;
}
//=========================================================
| |