题解 #字符串加密# 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
全部评论

相关推荐

点赞 评论 收藏
分享
06-17 00:26
门头沟学院 Java
程序员小白条:建议换下项目,智能 AI 旅游推荐平台:https://github.com/luoye6/vue3_tourism_frontend 智能 AI 校园二手交易平台:https://github.com/luoye6/vue3_trade_frontend GPT 智能图书馆:https://github.com/luoye6/Vue_BookManageSystem 选项目要选自己能掌握的,然后最好能自己拓展的,分布式这种尽量别去写,不然你只能背八股文了,另外实习的话要多投,尤其是学历不利的情况下,多找几段实习,最好公司title大一点的
无实习如何秋招上岸
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务