python - 如何在 python 程序上找到运行时错误错误
问题描述
所以我尝试用我的 python 代码解决https://open.kattis.com/problems/10kindsofpeople,我认为代码很好并且通过了 22/25 测试用例,但是在测试用例 23 中存在运行时错误。
代码在这里:
if __name__ == "__main__":
def walk(arr,r1,c1,r2,c2,rows,cols, history):
history['{0},{1}'.format(r1,c1)] = True
# print('{},{}-{},{}'.format(r1,c1,r2,c2))
if arr[r1][c1] == arr[r2][c2]:
if r1 == r2 and c1 == c2:
return True
if r1-1 >= 0 and '{0},{1}'.format(r1-1, c1) not in history:
atas = walk(arr, r1-1,c1,r2,c2,rows,cols,history)
else:
atas=False
if r1+1 < rows and '{0},{1}'.format(r1+1, c1) not in history:
bawah = walk(arr,r1+1,c1,r2,c2,rows,cols,history)
else:
bawah=False
if c1-1 >= 0 and '{0},{1}'.format(r1, c1-1) not in history:
kiri = walk(arr,r1,c1-1,r2,c2,rows,cols,history)
else:
kiri=False
if c1+1 < cols and '{0},{1}'.format(r1, c1+1) not in history:
kanan = walk(arr,r1,c1+1,r2,c2,rows,cols,history)
else:
kanan = False
# if one of them == true , there is a path to destination
if atas or bawah or kiri or kanan:
return True
else:
return False
else:
return False
map = input()
rows, cols = map.split(" ")
rows = int(rows)
cols = int(cols)
arr_row = []
for i in range(int(rows)):
str_inp = input()
list_int = [int(i) for i in str_inp]
arr_row.append(list_int)
coord_row=input()
coord_pair=[]
for i in range(int(coord_row)):
r1,c1,r2,c2 = input().split(" ")
coord_pair.append([r1,c1,r2,c2])
# print(arr_row)
for c in coord_pair:
r1 = int(c[0]) - 1
c1 = int(c[1]) - 1
r2 = int(c[2]) - 1
c2 = int(c[3]) - 1
history = {}
if arr_row[r1][c1] != arr_row[r2][c2]:
print("neither")
elif walk(arr_row, r1, c1, r2, c2, rows, cols, history):
ret = 'binary' if arr_row[r1][c1] == 0 else 'decimal'
print(ret)
else:
print('neither')
我认为隐藏测试用例的输入有错误,如果有人能找到错误,我将不胜感激,谢谢
解决方案
推荐阅读
- logstash - mongodb 是否有任何 Logstash 过滤器插件可以从多个集合中选择字段到一个 Elasticsearch 文档?
- android - 如何从颤动代码读取或访问在 android 代码中创建的共享首选项?
- graph - 标签传播算法是否有助于发现网络中的异常?
- c# - 从 ListBox 项中提取多个数组值
- docker - 如何让两个不同的用户处理 EF 核心迁移和 CRUD
- php - 如何将关联数组中键的值递增为字符串
- python-3.x - 由于条件,在时间序列图上绘制一条垂直线
- kotlin - 使用用户输入填充 Kotlin 中的类
- c - 具有两个条件的二叉搜索树
- amazon-web-services - aws ) 未定义符号:TLS_client_method