HJ29 字符串加解密
就是按照题目意思走,没有按照题解中的映射写
init_s = input()
sec_s = input()
def jiami(init_s,mode=True):
st=[]
for s in init_s:
## 是字母
if s.isalpha():
if ord('a') <= ord(s)<=ord('z'):
if mode:
if s=='z':
st.append('A')
else:
st.append(chr(ord(s)-31))
else:
if s=='a':
st.append('Z')
else:
st.append(chr(ord(s)-33))
else:##大写字母
if mode:
if s=='Z':
st.append('a')
else:
st.append(chr(ord(s)+33))
else:
if s=='A':
st.append('z')
else:
st.append(chr(ord(s)+31))
## 是数字
else:
if mode:
if s=='9':st.append('0')
else:
st.append(str(int(s)+1))
else:
if s=='0':st.append('9')
else:
st.append(str(int(s)-1))
return ''.join(st)
print(jiami(init_s,mode=True))
print(jiami(sec_s,mode=False))