题解 | #简单密码#

简单密码

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

import sys

alphas = 'abcdefghijklmnopqrstuvwxyz'
nums   = '22233344455566677778889999'
def cal(x):
    if x.isalpha()==False:
        out1 = x
    elif x.islower()==True:
        for i in range(len(alphas)):
            if x==alphas[i]:
                out1 = nums[i]
    else:
        for i in range(len(alphas)-1):
            if x.lower()==alphas[i]:
                out1 = alphas[i+1]
        if x.lower()=='z':
            out1 = 'a'
    return out1


for line in sys.stdin:
    a = line.split()[0]
    outa = ''

    for i in range(len(a)):
        ai = a[i:i+1]
        outa += cal(ai)
    print(outa)

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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