题解 | #字符串加密#
字符串加密
https://www.nowcoder.com/practice/e4af1fe682b54459b2a211df91a91cf3
//去重,新建表,找索引
const readline = require("readline");
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
let lines = [];
rl.on("line", function (line) {
//先去重
lines.push(line);
if (lines.length == 2) {
let key = new Set(lines[0].split(""));
let pwd = lines[1].split("");
let newList = [...key];
let oldList = "abcdefghijklmnopqrstuvwxyz";
for(let c of oldList){
if (!newList.includes(c)) {
newList.push(c);
}
}
// var line = "abcdefghijklmnopqrstuvwxyz";
// var list = Array.from(new Set(key + line));
//3、找索引
let res = [];
pwd.forEach((c) => {
let index = oldList.indexOf(c);
res.push(newList[index]);
});
//输出
console.log(res.join(""));
}
});
查看2道真题和解析