题解 | #字符串加解密#简单模拟

字符串加解密

http://www.nowcoder.com/practice/2aa32b378a024755a3f251e75cbf233a

def code(string):
    res = ''
    for x in string:
        if x.isdigit():
            res += str((int(x)+1)%10)
        elif x.isupper() and x != 'Z':
            res += chr(ord(x)+1).lower()
        elif x == 'Z':
            res += 'a'
        elif x.islower() and x != 'z':
            res += chr(ord(x)+1).upper()
        elif x == 'z':
            res += 'A'    
    return res

def decode(string):
    res = ''
    for x in string:
        if x.isdigit():
            res += str((int(x)-1)) if int(x)-1 >= 0 else '9'
        elif x.isupper() and x != 'A':
            res += chr(ord(x)-1).lower()
        elif x == 'A':
            res += 'z'
        elif x.islower() and x != 'a':
            res += chr(ord(x)-1).upper()
        elif x == 'a':
            res += 'Z'
    return res

while 1:
    try:
        s1, s2 = input(), input()
        print(code(s1))
        print(decode(s2))
    
    except:
        break
全部评论

相关推荐

06-25 09:33
厦门大学 Java
程序员饺子:现在日常估计没啥hc了,等到八月多估计就慢慢有了。双九✌🏻不用焦虑的
投递快手等公司7个岗位
点赞 评论 收藏
分享
完美的潜伏者许愿简历...:隐藏信息被你提取出来了,暗示,这就是暗示
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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