题解 | #简单密码#
简单密码
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; const alphToNum = { a: 2, b: 2, c: 2, d: 3, e: 3, f: 3, g: 4, h: 4, i: 4, j: 5, k: 5, l: 5, m: 6, n: 6, o: 6, p: 7, q: 7, r: 7, s: 7, t: 8, u: 8, v: 8, w: 9, x: 9, y: 9, z: 9, } void async function () { // Write your code here let val = ''; while(line = await readline()){ for (let i = 0; i < line.length; i++) { let str = line.charAt(i); if (/[a-z]/.test(str)) { val += alphToNum[str]; } else if (/[A-Z]/.test(str)) { // 大写转成小写 --- 小写转数字 + 1 ---转成字母 let b = str.toLowerCase().charCodeAt(0) + 1; str === 'Z' ? val += 'a' : val += String.fromCharCode(b); } else { // 数字和其它的符号都不做变换 val += str; } } console.log(val); } }()