Runtime error

0
0

一放到这里运行就出现Runtime error,但是在我自己的电脑上,我的是可以运行的,并且通过了例子的测试。我已经重新审视了下我的code,根据要求进行input和output。有谁可以帮助我,告诉我是什么问题呢? 附带我的python code在下面,谢谢。

""" step1: standard inputs """

while True:
    try:
        str_Num = input()
        x, y = (int(x) for x in input().split())

        N = len(str_Num)

""" step2: 2.1 create a list, called smallest. It has the same length as the str_Num from input, with initial value zeros, the purpose of it, for the positions/indexes that have "?", replace the value from 0-9 to find the smallest value for str_Num, s.t. int(str_Num) % X = Y 2.2 create a list of index_hasQuestionMark, treat the list as a stack. FILO. iterator the str_Num, the last position of the "?" push into the list, would be the smallest places/digits for the str_Num to change. ex: 12?4?6, the smallest places here is at index = 4, which is the tens place """

        smallest = [0] * N
        list_index_hasQuestionMark = []

        for pos in range(N):
            digit = str_Num[pos]
            if digit == "?":
                list_index_hasQuestionMark.append(pos)

""" step3: replace all of the "?" to "0", if the first digit is 0, replace to 1. initial state for str_Num """

        str_Num = str_Num.replace("?", "0")

        if str_Num[0] == "0":
            str_Num = "1" + str_Num[1:]

""" Step4: ---- pop the value from the stack: list_index_hasQuestionMark as a pos ---- check the value under smallest[pos] and put in the str_num to see if it works for int(str_Num) % X = Y ---- if equal: break inner loop and outer loop ---- else: increment the value by 1 in the smallest[pos] until reach to 9 """

        isFound = False
        while (list_index_hasQuestionMark):
            pos = list_index_hasQuestionMark.pop()
            while (smallest[pos] != 9):
                num = int(str_Num)
                reminder = num % x
                if (reminder != y):
                    smallest[pos] += 1
                    str_Num = str_Num[:pos] + str(smallest[pos]) + str_Num[pos + 1:]

                else:
                    isFound = True
                    break
            if isFound:
                break

        print(str_Num)

    except EOFError:
        break

0 answer(s)

write answer 切换为英文 切换为中文


转发分享