题解 | #字符串加解密#

字符串加解密

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
分享

创作者周榜

更多
牛客网
牛客企业服务