题解 #字符串加密# Python 代码力争优雅整洁

字符串加密

https://www.nowcoder.com/practice/e4af1fe682b54459b2a211df91a91cf3?tpId=37&&tqId=21259&rp=1&ru=/ta/huawei&qru=/ta/huawei/question-ranking

# 题目有些错别字
# Attack AT DAWN
# a b c d e f g h i j k l m n o p q r s t u v w x y z
# t r a i l b z e s c d f g h j k m n o p q u v w x y
# Tpptad TP ITVH
def f(s1,s2):
    lt = []
    for i in s1:
        if i not in lt:
            lt.append(i)
    for i in range(ord('a'),ord('z')+1):
        if chr(i) not in lt:
            lt.append(chr(i))

    dct = {}
    for i in range(ord('a'),ord('z')+1):
#         这里一度写为 lt[i] 导致  list out of range
        dct[chr(i)] = lt[i-ord('a')]

    out_lt=[]
    chang = len(s2)
    for i in range(chang): 
        cha = dct[s2[i]]
        if s2[i].isupper(): cha = cha.upper()
        out_lt.append(cha)

    out= ''.join(out_lt)
    print(out)
while 1:
    try:
        s1=input()
        s2=input()
        f(s1,s2)

    except Exception as e:
        if not isinstance(e,EOFError):
            print('leo_you_have_Error:  '  , e)
        break
全部评论

相关推荐

10-05 23:02
东北大学 Java
我说句实话啊:那时候看三个月培训班视频,随便做个项目背点八股,都能说3 40w是侮辱价
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务