题解 | #字符串加解密#
字符串加解密
https://www.nowcoder.com/practice/2aa32b378a024755a3f251e75cbf233a
# 记忆:获取字符对应的ACS码 ord() # 记忆:将ACS码转化为字符 chr() import re def Encode(String): new = '' for s in String: if len(re.findall(r'[a-y]',s)): s = chr(ord(s) + 1) s = s.upper() new += s elif s == 'z': new += 'A' elif len(re.findall(r'[A-Y]',s)): s = chr(ord(s) + 1) s = s.lower() new += s elif s == 'Z': new += 'a' elif len(re.findall(r'[0-8]',s)): s = str(int(s) + 1) new += s elif s == '9': new += '0' return new def Decode(String): new = '' for s in String: if len(re.findall(r'[b-z]',s)): s = chr(ord(s) - 1) s = s.upper() new += s elif s == 'a': new += 'Z' elif len(re.findall(r'[B-Z]',s)): s = chr(ord(s) - 1) s = s.lower() new += s elif s == 'A': new += 'z' elif len(re.findall(r'[1-9]',s)): s = str(int(s) - 1) new += s elif s == '0': new += '9' return new print(Encode(input())) print(Decode(input()))