题解 | #字符串加密# 添加大小写及空格判断
字符串加密
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 while ((line = await readline())) { var key = line.toLowerCase(); var msg = await readline(); var line = "abcdefghijklmnopqrstuvwxyz"; var list = Array.from(new Set(key + line)); const result = []; for (var i = 0; i < msg.length; i++) { if (msg[i] == " ") { result.push(" "); continue; } else { if (/[A-Z]/.test(msg[i])) { result.push(list[line.indexOf(msg[i].toLowerCase())].toUpperCase()); } else { result.push(list[line.indexOf(msg[i])]); } } } console.log(result.join("")); } })();