题解 | 简单密码

简单密码

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

import sys

for line in sys.stdin:
    a = line.split()
    # print(int(a[0]) + int(a[1]))
    password = a[0]
    trans = []
    # trans_dict = { #太麻烦
    #     2:['a','b','c'],
    #     3:['d','e','f'],
    #     4:['g','h','i'],
    #     5:['j','k','l'],
    #     6:['m','n','o'],
    #     7:['p','q','r','s'],
    #     8:['t','u','v'],
    #     9:['w','x','y','z']
    # }
    trans_dict = {
        "abc":2,
        "def":3,
        "ghi":4,
        "jkl":5,
        "mno":6,
        "pqrs":7,
        "tuv":8,
        "wxyz":9
    }
    # c_list = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
    for c in password:
        if c.isdigit():
            trans.append(c)
        elif c.islower():
            for k,v in trans_dict.items():
                if c in k:
                    c_trans = str(v)
                    trans.append(c_trans)
        elif c.isupper():
            # idx = c_list.index(c.lower()) 
            # c_trans = c_list[(idx+1) % len(c_list)]
            # trans.append(c_trans)
            if c == 'Z':
                trans.append('a')
            else:
                trans.append(chr(ord(c.lower())+1))
    print(''.join(trans))




全部评论

相关推荐

点赞 评论 收藏
分享
09-17 10:53
四川大学 C++
牛客91242815...:会写标书没有任何卵用,鉴定为横向垃圾导师的受害者
点赞 评论 收藏
分享
10-20 16:50
门头沟学院 Java
牛客68421677...:同是天涯沦落人啊,我也是26届0实习,不知道怎么办了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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