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 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
#include <iostream>
#include <cstdlib>
int main(int argc, char **argv)
{
if (argc != 3) {
std::cerr << "Usage: mappywap ROW COL\n";
return 0;
}
const int NROWS = 17, NCOLS = 30, WINDOW_SIZE = 9;
char map[NROWS][NCOLS+1] = {
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
"X XXX XXXXXXXXX X",
"XX$ XXXXXXXXXXX X",
"XXX XXXXXXXXX XXXX X",
"XXX XXXXXXXXX XXXXXX X",
"XX XXXXXXXX XXXXXXX XX",
"X XXXXXXXXXX XXXXX XXX",
"X XXXXXXXXXXXXXXXX XXX",
"X XXX XXXXXXXXXXX XXXXX",
"X XXX XXXXXXXXXXXXXX XXX",
"X XXX XXXXXXXXXXX XXX",
"XXXXXXX XXXX XXXXX",
"XXXXX XXXX XXXXXX",
"XXXX XXXXX XXXXXXXXXXXX",
"XXX XXXXXX XXXX X X",
"X XXXXXX X",
"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
};
int r = std::atoi(argv[1]);
int c = std::atoi(argv[2]);
int top = r - WINDOW_SIZE / 2;
int left = c - WINDOW_SIZE / 2;
if (top < 0)
top = 0;
else if (top + WINDOW_SIZE > NROWS)
top = NROWS - WINDOW_SIZE;
if (left < 0)
left = 0;
else if (left + WINDOW_SIZE > NCOLS)
left = NCOLS - WINDOW_SIZE;
for (int row = top; row < top + WINDOW_SIZE; row++) {
for (int col = left; col < left + WINDOW_SIZE; col++)
std::cout << map[row][col];
std::cout << '\n';
}
}
| |