我正在做Kattis测试(不同的编程挑战)。在使用示例数据时,我的代码有效。使用Kattis超级机密测试数据,我无法通过“错误答案”。没有给出更多信息。 Link to problem description
使用有限的错误数据,我很难找到我的错误。我在网上找到了一些行之有效的解决方案,但是如果我复制它们的全部代码,那一定会达到目的。
我的代码:
def exec():
def CLEAR(a):
register[31 - int(a)] = 0
return register
def SET(a):
register[31 - int(a)] = 1
return register
def OR(a,b):
x = register[31 - int(a)]
y = register[31 - int(b)]
if x == '?' or y == '?':
register[31 - int(a)] = '?'
elif x == 0 and y == 0:
register[31 - int(a)] = 0
else:
register[31 - int(a)] = 1
return register
def AND(a,b):
x = register[31 - int(a)]
y = register[31 - int(b)]
if x == '?' or y == '?':
register[31 - int(a)] = '?'
elif x == 1 and y == 1:
register[31 - int(a)] = 1
else:
register[31 - int(a)] = 0
return register
def instruction(argument, *args):
switcher = {
'CLEAR': CLEAR,
'SET': SET,
'OR': OR,
'AND': AND
}
func = switcher.get(argument)
return func(*args)
while True:
lines = int(input()) #Get lines
if lines == 0:
break
else:
register = ['?'] * 32
for x in range(lines): #loop through each line
line = input().split()
instruction(*line)
print(*register, sep = "")
exec()