题解 | #简单密码#
简单密码
https://www.nowcoder.com/practice/7960b5038a2142a18e27e4c733855dac
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 const map = { abc: 2, def: 3, ghi: 4, jkl: 5, mno: 6, pqrs: 7, tuv: 8, wxyz: 9, }; const reg1 = /[A-Z]/; const reg2 = /[a-z]/; const reg3 = /\d/; let s = ""; while ((line = await readline())) { for (let i in line) { const k = line[i]; if (reg1.test(k)) { // 大写 if (k !== 'Z') { s += String.fromCharCode(k.toLowerCase().charCodeAt() + 1); } else { s += 'a' } } else if (reg2.test(k)) { // 小写 const list = Object.entries(map); for (let j = 0, l = list.length; j < l; j++) { if (list[j][0].includes(k)) { s += list[j][1]; break; } } } else if (reg3.test(k)) { // 数字 s += k; } } } console.log(s); })();