题解 | #字符串加密#
字符串加密
https://www.nowcoder.com/practice/e4af1fe682b54459b2a211df91a91cf3
const rl = require("readline").createInterface({ input: process.stdin }); var iter = rl[Symbol.asyncIterator](); const readline = async () => (await iter.next()).value; void async function () { // Write your code here let line = await readline() const s = 'abcdefghijklmnopqrstuvwxyz' line = [...new Set([...new Set([...line]),...s])] // 将字符串set,再拼接a-z之后再set,再放入数组,得到第二行字母表,而s就是第一行字母表 let line2 = await readline() line2 = line2.split("").map(v => { if(!v) return v // 如果是空,则正常返回 let str = line[s.indexOf(v)] // 在第一行字母表中找到v的index,再用该index去找到第二行字母表的字母 if(s.indexOf(v) == -1){ // 如果找不到该字母,则是大写字母,转换一下就好了 str = str.toUpperCase() } return str }) console.log(line2.join("")) }()