python
2026-05-17 21:12:41
发布于:江苏
0阅读
0回复
0点赞
def main():
enc1 = input().strip() # 加密信息
plain1 = input().strip() # 对应的原信息
enc2 = input().strip() # 待翻译的加密信息
plain_to_cipher = {}
cipher_to_plain = {}
# 建立映射
for c, p in zip(enc1, plain1):
# 检查明文到密文的映射是否矛盾
if p in plain_to_cipher:
if plain_to_cipher[p] != c:
print("Failed")
return
# 检查密文到明文的映射是否矛盾
if c in cipher_to_plain:
if cipher_to_plain[c] != p:
print("Failed")
return
plain_to_cipher[p] = c
cipher_to_plain[c] = p
# 检查是否所有字母都在原信息中出现
if len(plain_to_cipher) != 26:
print("Failed")
return
# 翻译密文
result = []
for ch in enc2:
# 根据映射得到明文,由于映射完整,ch一定存在
result.append(cipher_to_plain[ch])
print(''.join(result))
if __name__ == "__main__":
main()
这里空空如也

有帮助,赞一个