#include <iostream> #include <algorithm> #include <queue> using namespace std;
const int maxN = 103;
char canvas[maxN][maxN]; bool reach[maxN][maxN];
struct dot { int x; int y; dot(int _x, int _y) :x(_x), y(_y) { } };
void drawLine(int x1, int y1, int x2, int y2) { if (x1 == x2 && y1 != y2) { for (int i = min(y1, y2); i <= max(y1, y2); i++) { if (canvas[i][x1] == '-') canvas[i][x1] = '+'; if (canvas[i][x1] == '+') continue; else canvas[i][x1] = '|'; } } if (y1 == y2 && x1 != x2) { for (int i = min(x1, x2); i <= max(x1, x2); i++) { if (canvas[y1][i] == '|') canvas[y1][i] = '+'; if (canvas[y1][i] == '+') continue; else canvas[y1][i] = '-'; } } }
int dx[4] = { 0, 0, 1, -1 }; int dy[4] = { 1, -1, 0, 0 };
void fillCanvas(int x, int y, char c, int m, int n) { for (int i = 0; i < n; i++) fill(reach[i], reach[i] + m, false);
dot ori(x, y); queue<dot> q; q.push(ori); while (!q.empty()) { dot temp = q.front(); q.pop(); int xx = temp.x, yy = temp.y; canvas[yy][xx] = c; for (int i = 0; i < 4; i++) { int xxx = temp.x + dx[i]; int yyy = temp.y + dy[i]; dot temp2(xxx, yyy); if (xxx >= 0 && xxx < m && yyy >= 0 && yyy < n && canvas[yyy][xxx] != '-' && canvas[yyy][xxx] != '+' && canvas[yyy][xxx] != '|' && reach[yyy][xxx] != true) { q.push(temp2); reach[yyy][xxx] = true; } } } }
int main() { int m, n, q; cin >> m >> n >> q; for (int i = 0; i < n; i++) { fill(canvas[i], canvas[i] + m, '.'); fill(reach[i], reach[i] + m, false); } for (int i = 0; i < q; i++) { int ops; cin >> ops; switch (ops) { case 0: { int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; drawLine(x1, y1, x2, y2); }break; case 1: { int x, y; cin >> x >> y; char c; cin >> c; fillCanvas(x, y, c, m, n); }break; default: break; } }
for (int i = n - 1; i >= 0; i--) { for (int j = 0; j < m; j++) cout << canvas[i][j]; cout << endl; }
return 0; }
|