题解 | #字符串加解密#
字符串加解密
http://www.nowcoder.com/practice/2aa32b378a024755a3f251e75cbf233a
def on(i):#加密函数
if i.isalpha():
if i == 'z':
return 'A'
elif i == 'Z':
return 'a'
elif i.isupper() :
j=chr(ord(i)+1).lower()
return j
elif i.islower() :
j=chr(ord(i)+1).upper()
return j
elif i.isdigit():
if int(i) == 9:
return 0
else :
j=int(i)+1
return j
else:
return i
def off(i):#解密函数
if i.isalpha():
if i == 'A':
return 'z'
elif i == 'a':
return 'Z'
elif i.isupper() :
j=chr(ord(i)-1).lower()
return j
elif i.islower() :
j=chr(ord(i)-1).upper()
return j
elif i.isdigit():
if int(i) == 0:
return 9
else:
j=int(i)-1
return j
else:
return i
while True:
try:
before=str(input())
after=str(input())
res_1=''
res_2=''
for i in before:
j=on(i)
res_1=res_1+str(j)
for i in after:
j=off(i)
res_2=res_2+str(j)
print(res_1)
print(res_2)
except:
break