题解 | #字符串加解密#
字符串加解密
https://www.nowcoder.com/practice/2aa32b378a024755a3f251e75cbf233a
s_1, s_2 = input(), input()
l_1, l_2 = len(s_1), len(s_2)
L_1, L_2 = list(s_1), list(s_2)
for j in range(l_1):
if L_1[j].isdigit():
if L_1[j] == '9':
L_1[j] = '0'
else:
L_1[j] = str(int(L_1[j]) + 1)
elif L_1[j].isalpha():
if L_1[j] == "z":
L_1[j] = "A"
elif L_1[j] == "Z":
L_1[j] = "a"
elif L_1[j].isupper():
L_1[j] = L_1[j].lower()
L_1[j] = chr(ord(L_1[j]) + 1)
elif L_1[j].islower():
L_1[j] = L_1[j].upper()
L_1[j] = chr(ord(L_1[j]) + 1)
print("".join(L_1))
for t in range(l_2):
if L_2[t].isdigit():
if L_2[t] == '0':
L_2[t] = '9'
else:
L_2[t] = str(int(L_2[t]) - 1)
elif L_2[t].isalpha():
if L_2[t] == "A":
L_2[t] = "z"
elif L_2[t] == "a":
L_2[t] = "Z"
elif L_2[t].isupper():
L_2[t] = L_2[t].lower()
L_2[t] = chr(ord(L_2[t]) - 1)
elif L_2[t].islower():
L_2[t] = L_2[t].upper()
L_2[t] = chr(ord(L_2[t]) - 1)
print("".join(L_2))
查看13道真题和解析