题解 | #字符串加密#

字符串加密

https://www.nowcoder.com/practice/e4af1fe682b54459b2a211df91a91cf3

key = input()
targetStr = input()
targetStrList = list(targetStr)
resultList = []
# 处理后的key
key1 = []
# 原字母表
alphaTablet = [
    "a",
    "b",
    "c",
    "d",
    "e",
    "f",
    "g",
    "h",
    "i",
    "j",
    "k",
    "l",
    "m",
    "n",
    "o",
    "p",
    "q",
    "r",
    "s",
    "t",
    "u",
    "v",
    "w",
    "x",
    "y",
    "z",
]
# 更新后的新字母表
newalphaTablet = []

for word1 in key:
    if word1 not in key1:
        key1.append(word1)
# 将处理后的key加入到新字母表开头
newalphaTablet = newalphaTablet + key1
# 更新新字母表
for word2 in alphaTablet:
    if word2 not in newalphaTablet:
        newalphaTablet.append(word2)
# 替换
for i in range(len(targetStrList)):
    for j in range(26):
        if alphaTablet[j] == targetStrList[i]:
            resultList.append(newalphaTablet[j])
            continue

print("".join(resultList))

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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