解题思路:

注意事项:
其实丁说的判断条件可有可无,因此代码把这部分注释掉了,若加上,则需删除后面的一行 matched_intel += 1
参考代码:

for i in range(4):
    suspect = [0 for _ in range(4)]
    matched_intel, suspect[i] = 0, 1
    if (suspect[1] == 0 and suspect[3] == 1) or \
        (suspect[1] == 1 and suspect[3] == 0):
        matched_intel += 1
    if (suspect[1] == 0 and suspect[2] == 1) or \
        (suspect[1] == 1 and suspect[2] == 0):
        matched_intel += 1
    if (suspect[0] == 0 and suspect[1] == 1) or \
        (suspect[0] == 1 and suspect[1] == 0):
        matched_intel += 1
    # if suspect[3] == 0 or suspect[3] == 1:
    #     matched_intel += 1
    matched_intel += 1
    if matched_intel == 4:
        res = dict(zip(suspect, "ABCD"))
        print(res[suspect[i]])
        break


 

0.0分

0 人评分

  评论区