题解 | #字符串加解密#
字符串加解密
https://www.nowcoder.com/practice/2aa32b378a024755a3f251e75cbf233a
s1 = list(input()) s2 = list(input()) def encryption(s, x): for i in range(len(s)): if s[i].isupper(): if x == 1 and s[i] == 'Z': s[i] = 'a' elif x == -1 and s[i] == 'A': s[i] = 'z' else: s[i] = chr(ord(s[i]) + 32 + x) elif s[i].islower(): if x == 1 and s[i] == 'z': s[i] = 'A' elif x == -1 and s[i] == 'a': s[i] = 'Z' else: s[i] = chr(ord(s[i]) - 32 + x) elif s[i].isdigit(): if x == 1 and s[i] == '9': s[i] = '0' elif x == -1 and s[i] == '0': s[i] = '9' else: s[i] = chr(ord(s[i]) + x) return (''.join(s)) print(encryption(s1, 1)) print(encryption(s2, -1))