题解 | #字符串加解密#简单模拟
字符串加解密
http://www.nowcoder.com/practice/2aa32b378a024755a3f251e75cbf233a
def code(string):
res = ''
for x in string:
if x.isdigit():
res += str((int(x)+1)%10)
elif x.isupper() and x != 'Z':
res += chr(ord(x)+1).lower()
elif x == 'Z':
res += 'a'
elif x.islower() and x != 'z':
res += chr(ord(x)+1).upper()
elif x == 'z':
res += 'A'
return res
def decode(string):
res = ''
for x in string:
if x.isdigit():
res += str((int(x)-1)) if int(x)-1 >= 0 else '9'
elif x.isupper() and x != 'A':
res += chr(ord(x)-1).lower()
elif x == 'A':
res += 'z'
elif x.islower() and x != 'a':
res += chr(ord(x)-1).upper()
elif x == 'a':
res += 'Z'
return res
while 1:
try:
s1, s2 = input(), input()
print(code(s1))
print(decode(s2))
except:
break