题解 | #字符串加密#

字符串加密

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

import sys

s1 = input()    #key
s2 = input()    #加密
#print(s1, s2)

# a-z字母表
l = []
for i in range(ord('a'), ord('z')+1):
    l.append(chr(i))
#print(l)

# s1去重
new = []
for i in s1:
    if i not in new:
        new.append(i)
#print(new)

# 新字母表
for i in l:
    if i not in new:
        new.append(i)
#print(new)      

# 原字母表和新字母表对应起来
# key:原字母表 value:新字母表
d = dict(zip(l,new))            #zip()将两个链表缝合在一起
#print(d)

# 加密s2
for i in s2:
    print(d[i],end='')

全部评论

相关推荐

酷酷的喜马拉雅山:感觉这比一直在初筛不动的好多了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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