题解 | #字符串加密#
字符串加密
http://www.nowcoder.com/practice/e4af1fe682b54459b2a211df91a91cf3
理解题意很重要
题意:将加密的字符串去重 设为a ,然后在26个字母 (设为 b) 中将加密中出现的字符剔除 设为c,然后a+c 是获取加密字符的字母表
需要加密的字符串 设为 d , d中出现的字母 在 b中查出对应的索引 ,拿索引然后去 c 中 查出对应的字母,将字母组成字符串则是加密后的字符串
def strings_passwd(key,strings): a = 'abcdefghijklmnopqrstuvwxyz' a = [_ for _ in a] d = a[:] b = set(key) c = list(sorted(b,key=key.index)) # print(c) for i in c : d.remove(i) e = c + d f = [] for i in strings: f.append(e[a.index(i)]) return ''.join(_ for _ in f) key = input().strip() strings = input().strip() print(strings_passwd(key,strings))