题解 | #字符串加解密#

字符串加解密

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

# #题解1
# import sys
# def encode(s):
#     encodes = ""
#     for c in s:
#         if c.isupper():
#             if c == 'Z':
#                 encodes += 'a'
#             else:
#                 encodes += chr(ord(c.lower()) + 1)
#         elif c.islower():
#             if c == 'z':
#                 encodes += 'A'
#             else:
#                 encodes += chr(ord(c.upper()) + 1)
#         elif c.isdecimal():
#             if c == '9':
#                 encodes += '0'
#             else:
#                 encodes += chr(ord(c) + 1)
#     return encodes

# def decode(s):
#     decodes = ""
#     for c in s:
#         if c.isupper():
#             if c == 'A':
#                 decodes += 'z'
#             else:
#                 decodes += chr(ord(c.lower()) - 1)
#         elif c.islower():
#             if c == 'a':
#                 decodes += 'Z'
#             else:
#                 decodes += chr(ord(c.upper()) - 1)
#         elif c.isdecimal():
#             if c == '0':
#                 decodes += '9'
#             else:
#                 decodes += chr(ord(c) - 1)
#     return decodes

# while True:
#     try:
#         toencodes = input().strip()
#         print(encode(toencodes))
#         todecodes = input().strip()
#         print(decode(todecodes))
#     except:
# #         print(sys.exc_info())
#         break



#题解2
intab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
ourtab= "bcdefghijklmnopqrstuvwxyzaBCDEFGHIJKLMNOPQRSTUVWXYZA1234567890"
encodeTrans = str.maketrans(intab,ourtab)
decodeTrans = str.maketrans(ourtab,intab)
while True:
    try:
        toencodes = input().strip()
        print(toencodes.translate(encodeTrans))
        todecodes = input().strip()
        print(todecodes.translate(decodeTrans))
    except:
        break








































全部评论

相关推荐

蚂蚁 基架java (n+6)*16 签字费若干
点赞 评论 收藏
分享
昨天 12:36
已编辑
门头沟学院 前端工程师
Apries:这个阶段来说,很厉害很厉害了,不过写的简历确实不是很行,优势删掉吧,其他的还行
点赞 评论 收藏
分享
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务