题解 | #字符串加解密#

字符串加解密

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

def jiami(a):
    aa=""
    for each in a:
        if each == '9':
            aa += '0'
            continue#进入下一个循环
        if 'a' <= each < 'z':
            each=chr(ord(each)+1)
            temp=each.upper()
            aa+=temp
            continue
        if each=='z':
            aa+='A'
            continue
        if 'A' <= each < 'Z':
            each=chr(ord(each)+1)
            temp=each.lower()
            aa+=temp
            continue
        if each=='Z':
            aa+='a'
            continue
        if '0'<=each<'9':
            each=chr(ord(each)+1)
            aa+=each
            continue
        else:
            aa+=each
            continue
        
    print(aa)

def jiemi(b):
    bb=""
    for each in b:
        if each == '0':
            bb += '9'
            continue
        if 'a' < each <= 'z':
            each=chr(ord(each)-1)
            temp=each.upper()
            bb+=temp
            continue
        if each=='a':
            bb+='Z'
            continue
        if 'A' < each <= 'Z':
            each=chr(ord(each)-1)
            temp=each.lower()
            bb+=temp
            continue
        if '0'<each<='9':
            each=chr(ord(each)-1)
            bb+=each
            continue
        if each=='A':
            bb+='z'
            continue
        else:
            bb+=each
            continue
        
    print(bb)

a=input()
b=input()
jiami(a)
jiemi(b)

直接暴力

全部评论

相关推荐

孤寡孤寡的牛牛很热情:为什么我2本9硕投了很多,都是简历或者挂,难道那个恶心人的测评真的得认真做吗
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务