求助!为什么RE

P5730 【深基5.例10】显示屏

huaizu @ 2024-02-11 20:57:45

n = int(input())

number = input()

digits = [

    ["XXX", "X.X", "X.X", "X.X", "XXX"],  # 0
    ["..X", "..X", "..X", "..X", "..X"],  # 1
    ["XXX", "..X", "XXX", "X..", "XXX"],  # 2
    ["XXX", "..X", "XXX", "..X", "XXX"],  # 3
    ["X.X", "X.X", "XXX", "..X", "..X"],  # 4
    ["XXX", "X..", "XXX", "..X", "XXX"],  # 5
    ["XXX", "X..", "XXX", "X.X", "XXX"],  # 6
    ["XXX", "..X", "..X", "..X", "..X"],  # 7
    ["XXX", "X.X", "XXX", "X.X", "XXX"],  # 8
    ["XXX", "X.X", "XXX", "..X", "XXX"]   # 9
]

result = [""] * 5

for digit in number:

    for i in range(5):
            result[i] += digits[int(digit)][i] + "."

for line in result:

    print(line[:-1])  # 去除最后一个点

by duomianti @ 2024-04-08 21:13:14

确实很奇怪,我一开始用列表推导式RE,后来改成双重循环就AC了,不懂原因,等大佬解答

一开始的:

n = int(input())
long = list(input())

# 二维列表保存数字点阵
line_n = [
            ['XXX','..X','XXX','XXX','X.X','XXX','XXX','XXX','XXX','XXX'],
            ['X.X','..X','..X','..X','X.X','X..','X..','..X','X.X','X.X'],
            ['X.X','..X','XXX','XXX','XXX','XXX','XXX','..X','XXX','XXX'],
            ['X.X','..X','X..','..X','..X','..X','X.X','..X','X.X','..X'],
            ['XXX','..X','XXX','XXX','..X','XXX','XXX','..X','XXX','XXX'],
        ]

for i in range(5):
    printlist = [line_n[i][int(j)] for j in long]
    # 输出的每个数字中间隔一个点
    print('.'.join(printlist))

修改后的(只改了其中一行):

n = int(input())
long = list(input())

# 二维列表保存数字点阵
line_n = [
            ['XXX','..X','XXX','XXX','X.X','XXX','XXX','XXX','XXX','XXX'],
            ['X.X','..X','..X','..X','X.X','X..','X..','..X','X.X','X.X'],
            ['X.X','..X','XXX','XXX','XXX','XXX','XXX','..X','XXX','XXX'],
            ['X.X','..X','X..','..X','..X','..X','X.X','..X','X.X','..X'],
            ['XXX','..X','XXX','XXX','..X','XXX','XXX','..X','XXX','XXX'],
        ]

for i in range(5):
    printlist = []
    for j in range(n):
        printlist.append(line_n[i][int(long[j])])
    # 输出的每个数字中间隔一个点
    print('.'.join(printlist))

by Cill @ 2024-04-09 11:06:18

由于洛谷的第二行输入加入了\r

例如输入是1234,则long会是1234\r,列表生成中int(\r)就RE了

|