题解 | #字符串加解密#

字符串加解密

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








































全部评论

相关推荐

珩珺:那些经历都太大太空了,实习的情况不了解,大创项目连名字、背景、目的及意义都没体现出来;地摊经济更是看完连卖的什么产品都不知道,项目成果直接写营收多少都更直观真实一点;后面那个校文体部的更是工作内容是组织活动整理流程,成果变成了当志愿者,而且你们学校本科学生会大一入学就直接当部长吗,志愿里面还提到了疫情防控,全面解封是22年12月的事情,可能时间上也有冲突。可能你花了钱人家就用AI给你随便写了点内容改了一下,没什么体现个性化的点
点赞 评论 收藏
分享
Clavoss:一眼AI,死亏
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务