题解 | #字符串加密#

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

table0= ['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']
def jiami(mishi,mingma):
    #实现去重
    list =sorted(set(mishi),key=mishi.index) #set去重了但是无序,按照原来的顺序排序
    #添加剩余字母,生成完整的新字母表
    table= ['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']
    s_low = []
    for i in list:
        s_low.append(i.lower())
        if i.lower() in table:
            table.remove(i.lower()) #remove会改变原来的table
    new_table = s_low + table 
    #输入明文
    out = str()
    for c in mingma:
        if c.isupper() == True:
            index = table0.index(c.lower())
            out += new_table[index].upper()
        else:
            index = table0.index(c)
            out += new_table[index]
    print(out)

mishi = list(input())
mingma = input()
jiami(mishi,mingma)
全部评论

相关推荐

10-28 14:42
门头沟学院 Java
watermelon1124:因为嵌入式炸了
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务