题解 | #字符串加密#

字符串加密

https://www.nowcoder.com/practice/e4af1fe682b54459b2a211df91a91cf3

def encode(string, key):
    head = ""
    # 得到不重复的头字符串
    for c in key:
        if c not in head:
            head += c

    base_str = "abcdefghijklmnopqrstuvwxyz"
    encrypt_str = head

    # 得到加密字符串
    for c in base_str:
        if c not in encrypt_str:
            encrypt_str += c

    # 得到对应字典
    encode_dict = {}
    for i in range(26):
        encode_dict[base_str[i]] = encrypt_str[i]

    res = ""
    for c in string:
        res += encode_dict[c]

    return res        


while True:
    try:
        key = input()
        string = input()
        print(encode(string, key))
    except:
        break

全部评论

相关推荐

04-28 11:34
西北大学 运营
牛客4396号:不好意思,这个照片猛一看像丁真
点赞 评论 收藏
分享
后来123321:别着急,我学院本大二,投了1100份,两个面试,其中一个还是我去线下招聘会投的简历,有时候这东西也得看运气
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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