题解 | #字符串加密#

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)
全部评论

相关推荐

头像
05-16 11:16
已编辑
东华理工大学 Java
牛客737698141号:盲猜几十人小公司,庙小妖风大,咋不叫她去4️⃣呢😁
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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