题解 | #字符串加解密#

字符串加解密

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))

全部评论

相关推荐

头像
11-18 16:08
福州大学 Java
影流之主:干10年不被裁,我就能拿别人一年的钱了,日子有盼头了
点赞 评论 收藏
分享
10-28 15:45
门头沟学院 C++
西南山:海康威视之前不是大规模裁员吗
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务