题解 | #简单密码#

简单密码

http://www.nowcoder.com/practice/7960b5038a2142a18e27e4c733855dac

一直使用if...elif,去匹配字符

s = input()
res = []
for i in s:
    if i.isdigit():
        res.append(i)
    elif i.isupper() and i != 'Z':
        res.append(chr(ord(i.lower()) + 1))
    elif i == 'Z':
        res.append('a')
    else:
        if i in 'abc':
            res.append('2')
        elif i in 'def':
            res.append('3')
        elif i in 'ghi':
            res.append('4')
        elif i in 'jkl':
            res.append('5')
        elif i in 'mno':
            res.append('6')
        elif i in 'pqrs':
            res.append('7')
        elif i in 'tuv':
            res.append('8')
        else:
            res.append('9')
print(''.join(res))

全部评论

相关推荐

2025-12-16 14:57
门头沟学院 Java
迷茫的大四🐶:是这样的,我都拿到你这同一水平的offer了,那我接你的offer的意义在哪,我一开始想接你们的offer期待是很高的,希望你们下次继续努力
你今年的保底offer是...
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务