题解 | #字符串加解密#

字符串加解密

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

def jiami(string):
    res = ""
    for c in string:
        if c == "z":
            res += "A"
        elif c == "Z":
            res += "a"
        elif "a" <= c <= "z":
            res += chr(ord(c.upper()) + 1)
        elif "A" <= c <= "Z":
            res += chr(ord(c.lower()) + 1)
        elif "0" <= c < "9":
            res += chr(ord(c) + 1)
        elif c == "9":
            res += "0"
    return res


def jiemi(string):
    res = ""
    for c in string:
        if c == "a":
            res += "Z"
        elif c == "A":
            res += "z"
        elif "a" <= c <= "z":
            res += chr(ord(c.upper()) - 1)
        elif "A" <= c <= "Z":
            res += chr(ord(c.lower()) - 1)
        elif "0" < c <="9":
            res += chr(ord(c) - 1)
        elif c == "0":
            res += "9"
    return res


str1 = str(input())
str2 = str(input())
print(jiami(str1))
print(jiemi(str2))

全部评论

相关推荐

点赞 评论 收藏
分享
10-07 20:48
门头沟学院 Java
听说改名就会有offer:可能是实习上着班想到后面还要回学校给导师做牛马,看着身边都是21-25的年纪,突然emo了了
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务