题解 | 字符串加密
字符串加密
https://www.nowcoder.com/practice/e4af1fe682b54459b2a211df91a91cf3
s = input() # 对照表,去重后补充未出现的字母在串尾,作为对照表对t进行替换加密 t = input() # 待加密字符串 def quchong(s: str): new_s = "" for char in s: if char not in new_s: new_s += char return new_s quchong_s = quchong(s) def alphalist():#懒得打字硬编码 alpha_li = "" i = 97 while i < 123: alpha_li += chr(i) i += 1 return alpha_li alpha_str = alphalist() end_s = "" # 最终参照表s end_s += quchong_s for char in alpha_str: if char not in quchong_s: end_s += char dict_s = dict(zip(alpha_str, end_s))#合并俩列表为字典,字母表对应参照表end_s encode_t = "" for char in t: encode_t += dict_s.get(char) print(encode_t)