题解 | #字符串加解密#
字符串加解密
https://www.nowcoder.com/practice/2aa32b378a024755a3f251e75cbf233a
import sys #注意大小写的逻辑,如果判断了特殊情况要直接continue,注意任何变量的类型 def encoding(s: str): for i in s: if i == '9'or i == "Z" or i == "z": if i == '9': L.append(str(0)) if i == "Z": L.append('a') if i == "z": L.append('A') # print(i) continue elif i.isupper(): i = i.lower() # 要先大小写变化 i = chr(ord(i) + 1) # print(i) elif i.islower(): i = i.upper() i = chr(ord(i) + 1) elif i.isnumeric(): i = str(int(i) + 1) L.append(i) return L def decoding(s: str): for i in s: if i == '0' or i == "A" or i == "a": if i == '0': LL.append(str(9)) if i == "A": LL.append('z') if i == "a": LL.append('Z') # print(i) continue elif i.isupper(): i = i.lower() # 要先大小写变化 i = chr(ord(i) -1) # print(i) elif i.islower(): i = i.upper() i = chr(ord(i) -1) # print(i) elif i.isnumeric(): i = str(int(i) -1) # print(i) LL.append(i) # print(LL) return LL s1 = input().strip() L=[] print("".join(encoding(s1))) LL=[] s2 = input().strip() print("".join(decoding(s2)))