题解 | #字符串加解密#
字符串加解密
http://www.nowcoder.com/practice/2aa32b378a024755a3f251e75cbf233a
'''
没难度,就是条件语句用的有点多,O(∩_∩)O哈哈~
'''
i1=list(input())
lt1=[]i2=list(input())
lt2=[]
for w1 in i1:
if w1.isalpha():
if w1.islower():
if w1=='z':
lt1.append('A')
else:
lt1.append(chr(ord(w1.upper())+1))
elif w1.isupper():
if w1=='Z':
lt1.append('a')
else:
lt1.append(chr(ord(w1.lower())+1))
elif w1.isdigit():
if w1=='9':
lt1.append('0')
elif w1 in ['0','1','2','3','4','5','6','7','8']:
lt1.append(str(int(w1)+1))
else:
lt1.append(w1)
for w2 in i2:
if w2.isalpha():
if w2.islower():
if w2=='a':
lt2.append('Z')
else:
lt2.append(chr(ord(w2.upper())-1))
elif w2.isupper():
if w2=='A':
lt2.append('z')
else:
lt2.append(chr(ord(w2.lower())-1))
elif w2.isdigit():
if w2=='0':
lt2.append('9')
elif w2 in ['1','2','3','4','5','6','7','8','9']:
lt2.append(str(int(w2)-1))
else:
lt1.append(w2)
print(''.join(lt1))
print(''.join(lt2))
【牛客站内】华为机试题—中等 文章被收录于专栏
【牛客站内】华为机试题练习记录