题解 | #字符串加解密#
字符串加解密
https://www.nowcoder.com/practice/2aa32b378a024755a3f251e75cbf233a
import sys def code(c):#加密函数 for i in range(len(c)): if c[i].isdigit(): c[i]=str((int(c[i])+1)%10) else: if c[i].isupper(): if c[i]=='Z': c[i]='a' else: c[i]=chr(ord(c[i])+1).lower() else: if c[i]=='z': c[i]='A' else: c[i]=chr(ord(c[i])+1).upper() print(''.join(c)) def encode(c):#解密函数 for i in range(len(c)): if c[i].isdigit(): if int(c[i])==0: c[i]='9' #要注意是字符不是数字,否则会报错 else: c[i]=str(int(c[i])-1) else: if c[i].isupper(): if c[i]=='A': c[i]='z' else: c[i]=chr(ord(c[i])-1).lower() else: if c[i]=='a': c[i]='Z' else: c[i]=chr(ord(c[i])-1).upper() print(''.join(c)) a=list(input()) b=list(input()) code(a) encode(b)