题解 | #字符串加解密#
字符串加解密
http://www.nowcoder.com/practice/2aa32b378a024755a3f251e75cbf233a
python3解题
def encryption(s1):
tmp = []
for i in s1:
if 'a'<=i<='z':
if i == 'z':
tmp.append('A')
else:
tmp.append((chr(ord(i)+1)).upper())
elif 'A'<=i<='Z':
if i == 'Z':
tmp.append('a')
else:
tmp.append((chr(ord(i)+1)).lower())
else:
if int(i) == 9:
tmp.append(0)
else:
tmp.append(int(i)+1)
for i in tmp:
print(i,end='')
def decryption(s2):
tmp = []
for i in s2:
if 'a'<=i<='z':
if i == 'a':
tmp.append('Z')
else:
tmp.append((chr(ord(i)-1)).upper())
elif 'A'<=i<='Z':
if i == 'A':
tmp.append('z')
else:
tmp.append((chr(ord(i)-1)).lower())
else:
if int(i) == 0:
tmp.append(9)
else:
tmp.append(int(i)-1)
for i in tmp:
print(i,end='')
s1 = input()
s2 = input()
encryption(s1)
print('')
decryption(s2)