字符串加密
字符串加密
http://www.nowcoder.com/questionTerminal/e4af1fe682b54459b2a211df91a91cf3
while True:
try:
keys,encrypt = input().upper(),input()
a ,table= "",{}
alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
for i in keys:
if i not in a:
a += i
newStr = a
for i in alpha:
if i not in newStr:
newStr += i
for i in range(len(newStr)):
table[alpha[i]] = newStr[i]
# 加密过程
res = ""
for i in range(len(encrypt)):
if encrypt[i] in table.keys():
for k,v in table.items():
if k == encrypt[i]:
res += v
elif not encrypt[i].isalpha():
res += encrypt[i]
else:
for k,v in table.items():
if k == encrypt[i].upper():
res += v.lower()
print(res)
except:
break
查看12道真题和解析
巨人网络成长空间 53人发布
