题解 | #简单密码#

简单密码

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

while 1:
    try:
        passwd =  input().strip()
        passwd = list(passwd)
        for i in range(len(passwd)):
            asci = ord(passwd[i])
            if asci>=ord('a') and asci<=ord('z'):#当前字符为小写字母
                if asci>=ord('a') and asci<=ord('c'):
                    passwd[i] = 2
                elif asci>=ord('d') and asci<=ord('f'):
                    passwd[i] = 3
                elif asci>=ord('g') and asci<=ord('i'):
                    passwd[i] = 4
                elif asci>=ord('j') and asci<=ord('l'):
                    passwd[i] = 5
                elif asci>=ord('m') and asci<=ord('o'):
                    passwd[i] = 6
                elif asci>=ord('p') and asci<=ord('s'):
                    passwd[i] = 7
                elif asci>=ord('t') and asci<=ord('v'):
                    passwd[i] = 8
                elif asci>=ord('w') and asci<=ord('z'):
                    passwd[i] = 9
            elif asci>=ord('A') and asci<=ord('Z'):#当前字符为小写字母
                if passwd[i].lower() == 'z':
                    passwd[i] = 'a'
                else:
                    passwd[i] = chr(ord(passwd[i].lower())+1)
        istr = ''
        for i in passwd:
            istr+=str(i)
            
        print(istr)
    except EOFError:
        break
全部评论
chr() 函数根据ascaii码求字符, ord()函数根据字符求ascaii码
点赞 回复 分享
发布于 2021-10-27 23:29

相关推荐

喜欢走神的孤勇者练习时长两年半:池是池,发是发,我曾池,我现黑
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务