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()

猜你喜欢

转载自blog.csdn.net/qq_39577481/article/details/83988595