题解 | #字符串加密#
字符串加密
http://www.nowcoder.com/practice/e4af1fe682b54459b2a211df91a91cf3
** 踩坑指南:大写和小写要分别去重和放首位,大写的提取key之后,剩下的大写依次往后排。 小写的提取key后,剩下的小写字母依次往后排。 26个大写字母放前面,26个小写字母放后面,对应位置进行替换输出。 **
s = input()
s2 = input()
lower_list = []
upper_list = []
for x in s:
if x >= "A" and x <= "Z" and x not in upper_list:
upper_list.append(x)
elif x >= "a" and x <= "z" and x not in lower_list:
lower_list.append(x)
all_list_p1 = [chr(i) for i in range(65,128) if chr(i) >= 'A' and chr(i) <= 'Z']
all_list_p2 = [chr(i) for i in range(65,128) if chr(i) >= 'a' and chr(i) <= 'z']
all_list = all_list_p1 + all_list_p2
all_list2_lower = [x for x in all_list_p2 if x not in lower_list]
all_list2_upper = [x for x in all_list_p1 if x not in upper_list]
all_list3 = upper_list + all_list2_upper + lower_list + all_list2_lower
# print(all_list3)
result_list = []
for x in s2:
result_list.append(all_list3[all_list.index(x)])
print("".join(result_list))