题解 | #简单密码# python优雅
简单密码
http://www.nowcoder.com/practice/7960b5038a2142a18e27e4c733855dac
import sys _d1={ 'abc':2, 'def':3, 'ghi':4, 'jkl':5, 'mno':6,'pqrs':7,'tuv':8,'wxyz':9 } _d2={} for k,v in _d1.items(): for s in k: # 记得加str _d2[s]=str(v) def map_func(c): ot=c # if ord(c) in range(ord('A'),ord('Z')+1): # if 'A'<= c <='Z': if c.isupper(): if c.lower()=='z': ot= 'a' else: ot=chr(ord(c.lower())+1) # elif ord(c) in range(ord('a'),ord('z')+1): elif c.islower(): ot=_d2[c] else: pass return ot for line in sys.stdin: l=list(line.strip()) main_ot=''.join(list(map(map_func,l))) print(main_ot)