80分求调
查看原帖
80分求调
1291183
Ltfh_Inf楼主2024/12/2 21:35
stack_in = list(input().strip())
stack_out = []

i = 0
while (i != len(stack_in)):
    temp_1 = stack_in[i]
    if temp_1 == "]":
        temp_str = ""
        top = stack_out.pop()
        top = top[::-1]
        while top != "[":
            temp_str = temp_str + top
            top = stack_out.pop()

        temp_str = temp_str[::-1]
        temp_num = temp_str[0:2]
        if temp_num.isdigit():
            num = int(temp_num)
            stack_out.append(num * temp_str[2:])

        else:
            num = int(temp_num[0])
            stack_out.append(num * temp_str[1:])

        i += 1

    else:
        stack_out.append(temp_1)
        i += 1

for x in stack_out:
    print(x, end="")

2024/12/2 21:35
加载中...