weixin_46004223 2022-05-23 18:11 采纳率: 0%
浏览 205

PTA超时问题,想问一下怎么解决

在PTA平台运行时出现超时问题

from collections import deque
s = input()
index = 0
now = deque()

isRepeat = False
for x in s:
    if x == '[':
        index = 0
    elif x == ']':
        index = len(now)
    elif x == '{':
        if index > 0:
            index -= 1
    elif x == '}':
        if index < len(now):
            index += 1
    elif x == '-':
        isRepeat = not isRepeat
    elif x == '=':
        now.rotate(-(index-1))
        now.popleft()
        now.rotate(index - 1)
        index -= 1
    else:
        if isRepeat:
            now.rotate(-index)
            now.popleft()
            now.appendleft(x)
            now.rotate(index)
        else:
            now.rotate(-index)
            now.appendleft(x)
            now.rotate(index)
        index += 1

print("".join(now))


编译结果时显示有超时问题

img

请问有没有人能指点一下

  • 写回答

2条回答 默认 最新

  • weixin_46004223 2022-05-23 18:25
    关注

    输入样例
    jilin[i lofe{{-v-} ] universiti=y
    abcd[c-de
    [[]][][]happy=birthday
    efg[bbb}}=}}}}=[{{{{a

    评论

报告相同问题?

问题事件

  • 创建了问题 5月23日