题解 | #简单密码#
简单密码
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 () { //后移逻辑 function move(index) { if(index==='z') { return 'a' } else { return String.fromCharCode(index.charCodeAt(0) + 1); } } //小写转数字 function zh(index) { let ar=['abc','def','ghi','jkl','mno','pqrs','tuv','wxyz'] for(let i=0;i<8;i++) { if(ar[i].includes(index)) { return i+2 } } } //判定逻辑 function judge(str){ //构建字符集 let rel1=/[a-z]/ //小写 let rel2=/[A-Z]/ //大写 let arr=[] for(let i of str) { if(i.match(rel2))//大写改小写,并 { arr.push( move(i.toLowerCase())) } else if(i.match(rel1))//小写转数字 { arr.push(zh(i)) } else { arr.push(i) } } return arr.join('') } while(line = await readline()){ //拿输入,转化为数组 let input =line.split('') console.log(judge(input)) } }()