乐鑫笔试更正输入

题意:四次存在错误的输入,还原正确的输入

输入案例:

aBcfef
abCdef
abcDef
abcEef

输出: 

 abcdef

如果存在某个字符四次均不一样,则无法还原,输出 Input Error

strings = []
res = ''
flag = 0
for _ in range(4):
    strings.append(input().strip())
for i in range(len(strings[0])):
    d = {}
    for j in range(len(strings)):
        if strings[j][i] not in d:
            d[strings[j][i]]=1
        else:
            d[strings[j][i]] += 1
    for key, value in d.items():
        if (value == max(d.values())):
            if value != 1:
                res += key
            else:
                flag = 1
                break
    if flag == 1:
        break
if flag == 1:
    print("Input Error")
else:
    print(res)

'''
aBcdef
abCdef
abcDef
abcEef
'''

 

你可能感兴趣的:(Python)