题解 | #字符串加密#
字符串加密
http://www.nowcoder.com/practice/e4af1fe682b54459b2a211df91a91cf3
k, v = input().strip(), input().strip()
kl = sorted(set(list(k)), key=k.index) # 密匙去重,并且不改变位置
al = [chr(i) for i in range(ord("a"), ord("z") + 1)] # a-z
vl = sorted(set(al).difference(set(kl))) # 密匙差集
kl.extend(vl) # 密匙补全
kv_d = {al[i]:kl[i] for i in range(26)} # 建立密匙字典,k为a-z,v为字母对应的密匙值
print("".join([kv_d[i] for i in v]))