题解 | #字符串加密#
字符串加密
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); }