题解 | #字符串加解密#

字符串加解密

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

# 记忆:获取字符对应的ACS码 ord()
# 记忆:将ACS码转化为字符   chr()
import re

def Encode(String):
    new = ''
    for s in String:
        if len(re.findall(r'[a-y]',s)):
            s = chr(ord(s) + 1)
            s = s.upper()
            new += s
        elif s == 'z':
            new += 'A'
        elif len(re.findall(r'[A-Y]',s)):
            s = chr(ord(s) + 1)
            s = s.lower()
            new += s
        elif s == 'Z':
            new += 'a'
        elif len(re.findall(r'[0-8]',s)):
            s = str(int(s) + 1)
            new += s
        elif s == '9':
            new += '0'
    return new

def Decode(String):
    new = ''
    for s in String:
        if len(re.findall(r'[b-z]',s)):
            s = chr(ord(s) - 1)
            s = s.upper()
            new += s
        elif s == 'a':
            new += 'Z'
        elif len(re.findall(r'[B-Z]',s)):
            s = chr(ord(s) - 1)
            s = s.lower()
            new += s
        elif s == 'A':
            new += 'z'
        elif len(re.findall(r'[1-9]',s)):
            s = str(int(s) - 1)
            new += s
        elif s == '0':
            new += '9'
    return new


print(Encode(input()))
print(Decode(input()))




全部评论

相关推荐

点赞 评论 收藏
分享
09-14 17:23
门头沟学院
故事和酒66:所以说副业很重要,程序员干到40岁,再怎么也赚300万了,吃吃利息也够活下去
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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