【发布时间】:2016-12-27 20:37:24
【问题描述】:
所以我决定在 CodeChef 上从事有竞争力的编程工作。我看到了一个要尝试的问题。但是我不断收到运行时错误(NZEC),我不知道为什么,因为我认为只有在调用超出绑定数组项和无限循环时才会发生错误,这会占用太多内存。
问题
1.) 获得 2 个输入 A 和 B
2.) 边界:1 ≤ B
3.) 然后我做 A-B 并更改答案的一位数
4.) 然后我把它退回去
注意: 时间限制为 1 秒,最大源代码大小 50,000 字节
例如
input A >> 95
input B >> 50
output >> 35
实际答案是 45,但我们打算更改答案的一位数
这就是我的解决方案
from random import randint
test1 = True
test2 = True
while test1:
A = int(input("Enter a number: "))
if (A>=1) and (A<=10000):
test1 = False
else:
print("Number must be greater or equal to 1 and less than or equalts to 10,000")
while test2:
B = int(input("Enter a second number: "))
if (B>=1) and (B<=10000) and (B<A):
test2 = False
else:
print("Number must follow rules as above BUT must be less than your first")
solution = str(A-B)
range1 = randint(0, len(solution)-1)
range2 = randint(0,9)
replacement = list(range(0,10))
new_solution = solution.replace(solution[range1], str(replacement[range2]))
print(new_solution)
【问题讨论】:
标签: python python-3.x runtime-error