题解 | #坐标移动#
简单密码
http://www.nowcoder.com/practice/7960b5038a2142a18e27e4c733855dac
import string
lower_case = [i.strip() for i in str(string.ascii_lowercase)]
upper_case = [i.strip() for i in str(string.ascii_uppercase)]
key_board = {1: "1", 2: "abc", 3: "def",
4: "ghi", 5: "jkl", 6: "mno",
7: "pqrs", 8: "tuv", 9: "wxyz", 0: "0"}
res = ""
while True:
try:
s = input()
for i in s.strip():
if i in lower_case:
for key, val in key_board.items():
if i in val:
res += str(key)
elif i in upper_case:
for key, val in key_board.items():
if val.count(i.lower()) > 0:
index = val.index(i.lower())
if index < len(val)-1:
res += key_board[key][index+1]
elif index == len(val)-1:
if key == 9:
res += "a"
else:
res += key_board[key+1][0]
else:
res += i
print(res)
except:
break
查看7道真题和解析