题解 | 字符串加密

const rl = require("readline").createInterface({
    input: process.stdin,
    output: process.stdout,
});
var iter = rl[Symbol.asyncIterator]();

const readline = async () => (await iter.next()).value;

void (async function () {
    let s = await readline();
    let t = await readline();
    let uniqueS = Array.from(new Set(s));
    let alphabet = "abcdefghijklmnopqrstuvwxyz".split("");
    let newAlphabet = uniqueS
        .filter((letter) => alphabet.includes(letter))
        .concat(alphabet.filter((letter) => !uniqueS.includes(letter)))
        .join("");
    let encrypted = t
        .split("")
        .map((char) => {
            let index = alphabet.indexOf(char);
            return newAlphabet[index];
        })
        .join("");
    console.log(encrypted);
})();

全部评论

相关推荐

点赞 评论 收藏
分享
2024-12-14 14:51
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务