画图


#include <iostream>
#include <cstring>

using namespace std;

int dir[4][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

const int N = 100+5;

char Map[N+1][N+1];

void fill(int x, int y, char c, int m, int n) {
	int nx, ny;

	Map[y][x] = c;

	for(int i=0; i<4; i++) {
		ny = y + dir[i][1];
		nx = x + dir[i][0];
		if(nx <0 || nx >=m || ny<0 || ny >=n || Map[ny][nx] == '|' || Map[ny][nx] == '-' || Map[ny][nx] == '+' || Map[ny][nx] == c)continue;

		fill(nx, ny, c, m, n);
	}
}



int main() {
	int m, n, q, op;
	int x1, y1, x2, y2;

	char c;
	memset(Map, '.', sizeof(Map));

	cin >> m >> n >> q;
	for(int i=1; i<=q; i++) {
		cin >> op;

		if(op == 0) {
			cin >> x1 >> y1 >> x2 >> y2;
			int start, end;
			if(x1 == x2) {
				start = min(y1, y2);
				end = max(y1, y2);

				for(int j=start; j<=end; j++)
					if(Map[j][x1] == '-' || Map[j][x1] == '+')
						Map[j][x1] = '+';
					else
						Map[j][x1] = '|';
			} else if(y1 == y2) {
				start = min(x1, x2);
				end = max(x1, x2);

				for(int j=start; j<=end; j++)
					if(Map[y1][j] == '|' || Map[y1][j] == '+')
						Map[y1][j] = '+';
					else
						Map[y1][j] = '-';
			}
		} else if(op == 1) {
			cin >> x1 >> y1 >> c;

			fill(x1, y1, c, m, n);
		}
	}

	for(int i=n-1; i>=0; i--) {
		for(int j=0; j<m; j++)
			cout << Map[i][j];
		cout << endl;
	}
	return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值