CCF Python题解(90分)201512-3 画图

CCF Python题解(90分)201512-3 画图

m, n, q = map(int, input().split())
canvas = [['.'] * m for i in range(n)]
emoj = ['-', '|', '+']


def fill(x, y, c):
    if x == m or y == n or x == -1 or y == -1:
        return
    row = n - 1 - y
    direct = [(-1, 0), (1, 0), (0, -1), (0, 1)]
    if canvas[row][x] not in emoj and (x, y) not in list2:
        list2.append((x, y))
        canvas[row][x] = c
        for i in direct:
            fill(x + i[0], y + i[1], c)
    list2.append((x, y))


for i in range(q):
    data = input().split()
    if data[0] == '0':
        x1, y1, x2, y2 = map(int, data[1:])
        if x1 == x2:

            for j in range(n - 1 - max(y1, y2), n - min(y1, y2)):
                if canvas[j][x1] == '-' or canvas[j][x1] == '+':  # 未考虑原来是+
                    canvas[j][x1] = '+'

                else:
                    canvas[j][x1] = '|'

        else:
            row = n - 1 - y1
            for j in range(min(x1, x2), max(x1, x2) + 1):

                if canvas[row][j] == '|' or canvas[row][j] == '+':
                    canvas[row][j] = '+'

                else:
                    canvas[row][j] = '-'

    else:
        x, y = map(int, data[1:3])
        c = data[3]
        list2 = []
        fill(x, y, c)

for i in range(n):
    for j in range(m):
        print(canvas[i][j], end="")
    print()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值