题解 | #字符串加密#

字符串加密

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


const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let index = 0
let key = ""
let str = ""
rl.on('line', function (line) {
    index++
    if (index === 1) {
        key = line
    }
    if (index === 2) {
        str = line
        solution()
    }
});
function solution() {
    let chars = Array.from(new Set(key))
    let origin = "abcdefghijklmnopqrstuvwxyz".split("")
    let trans = chars.slice()
    for (const char of origin) {
        if (!chars.includes(char)) {
            trans.push(char)
        }
    }
    let entries = origin.map((x, index) => [x, trans[index]] as [string, string])
    let map = new Map(entries)
    let res = str.split("").map(x => map.get(x)!).join("")
    console.log(res);

}


全部评论

相关推荐

11-05 07:29
贵州大学 Java
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务