题解 | #简单密码#

简单密码

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

import sys

a=input()
if len(a)==0 or len(a)>100:
    print('input out of range!')
    sys.exit()
b=[]
for i in a:
    if i>='A' and i<='Z':
        if i=='Z':
            b.append('a')
        else:
            tmp=i.lower()
            tmp=chr(ord(tmp)+1)
            b.append(tmp)
    elif i>='a' and i<'s':
        asc_num=ord(i)
        count=asc_num-ord('a')+0.1
        # a=0.1,b=1.1,c=2.1
        new_num=int(count/3)+2
        # abc:0+2,def:1+2
        b.append(str(new_num))
    elif i>='s'and i<='y':
        if i=='s':
            b.append('7')
        else:
            asc_num=ord(i)
            count=asc_num-ord('t')
            # t=0.1,u=1.1,v=2.1
            new_num=int(count/3)+8
            # tuv:0+8,wxy:1+8
            b.append(str(new_num))
    elif i=='z':
        b.append('9')
    else:
        b.append(i)
print(''.join(b))

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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