题解 | #字符串加解密#

字符串加解密

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

def encrypt(s):
    st=''
    for item in s:
        if item=='Z':
            st+="a"
            continue
        if item=="z":
            st+='A'
            continue
        if item=='9':
            st+='0'
            continue
        tem=ord(item)
        if 65<=tem and tem<90:
            st+=chr(tem+33)
        elif 97<=tem and tem<122:
            st+=chr(tem-31)
        elif 47<tem and tem<57:
            st+=chr(tem+1)
        else:
            st+=item
    return st
 
    
def decrypt(s):
    st=''
    for item in s:
        if item=='a':
            st+="Z"
            continue
        if item=="A":
            st+='z'
            continue
        if item=='0':
            st+='9'
            continue
        tem=ord(item)
        if 65<tem and tem<=90:
            st+=chr(tem+31)
        elif 97<tem and tem<=122:
            st+=chr(tem-33)
        elif 48<tem and tem<=57:
            st+=chr(tem-1)
        else:
            st+=item
    return st


while True:
    try:
        str1=input()
        str2=input()
        print(encrypt(str1))
        print(decrypt(str2))
        pass
    except:
        break
全部评论

相关推荐

嵌入式小辣鸡:包装好一点,校内的奖项可以不用写,校内项目经历最后两点写的太差了,详细讲一下内容,名字变一下。只需要写项目实现了什么,自己在其中做了什么就好,查看图片
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
7
2
分享

创作者周榜

更多
牛客网
牛客企业服务