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
|
#include <algorithm> // for min_element and max_element
#include <iostream> // cout, endl
#include <set>
#include <vector>
#include <utility> // pair and make_pair
using namespace std;
int main()
{
const int size = 15;
int x[size] = {0,4,8,12,16,20,24,28,32,36,40,44,48,52,56};
int y[size] = {0,5,10,10,13,18,20,20,25,0,-5,-10,-12,-16,-20};
// calculate minima and maxima.
int minx = *min_element( x, x+size );
int maxx = *max_element( x, x+size );
int miny = *min_element( y, y+size );
int maxy = *max_element( y, y+size );
// create an empty set of points
set<pair<int,int>> points;
// insert the points given be the above arrays
for ( size_t i = 0; i < size; ++i )
points.insert( make_pair( x[i], y[i] ) );
// display the points with stars.
for ( int iy = maxy; iy >= miny; --iy )
{
for ( int ix = minx; ix <= maxx; ++ix )
cout << ( points.count( make_pair( ix, iy ) ) ? '$' : ' ' );
cout << endl;
}
}
|