方法一(Python语言):
keyboard = {
1:',.',
2:'abc',
3:'def',
4:'ghi',
5:'jkl',
6:'mno',
7:'pqrs',
8:'tuv',
9:'wxyz',
0:' '
}
def fun(s):
result = []
mode = 1 # 1:数字 0:字母
tmpL = list(s)
stack = []
def out(mode):
nonlocal stack
if mode:
while stack:
result.append(stack.pop(0))
else:
lenStack = len(stack)
lenMap = len(keyboard[int(stack[-1])])
result.append(keyboard[int(stack[-1])][(lenStack % lenMap) - 1])
stack = []
while tmpL or stack:
if not tmpL: # 只有sta