题解 | #字符串加解密#

字符串加解密

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

s1 = input()
s2 = input()


upper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
lower = 'abcdefghijklmnopqrstuvwxyz'


# 加密
s1_y = ""
for i in s1:
    if i in upper:
        if i == 'Z':
            s1_y += 'a'
        else:
            index2 = upper.index(i)+1
            s1_y += lower[index2]
    elif i in lower:
        if i == 'z':
            s1_y += 'A'
        else:
            index1 = lower.index(i)+1
            s1_y += upper[index1]
    else:
        if i == '9':
            s1_y += '0'
        else:
            s1_y += str(int(i)+1)


#解密
s2_y = ""
for i in s2:
    if i in upper:
        if i == 'A':
            s2_y += 'z'
        else:
            index2 = upper.index(i)-1
            s2_y += lower[index2]
    elif i in lower:
        if i == 'a':
            s2_y += 'Z'
        else:
            index1 = lower.index(i)-1
            s2_y += upper[index1]
    else:
        if i == '0':
            s2_y += '9'
        else:
            s2_y += str(int(i)-1)

print(s1_y)
print(s2_y)

全部评论

相关推荐

点赞 评论 收藏
分享
11-09 01:22
已编辑
东南大学 Java
高级特工穿山甲:羡慕,我秋招有家企业在茶馆组织线下面试,约我过去“喝茶详谈”😢结果我去了发现原来是人家喝茶我看着
点赞 评论 收藏
分享
把球:这个听过,你加了就会发现是字节的hr
点赞 评论 收藏
分享
1 收藏 评论
分享
牛客网
牛客企业服务