题解 | #简单密码#
简单密码
https://www.nowcoder.com/practice/7960b5038a2142a18e27e4c733855dac?tpId=37&tqId=21244&rp=1&ru=/exam/oj/ta&qru=/exam/oj/ta&sourceUrl=%2Fexam%2Foj%2Fta%3FtpId%3D37&difficulty=undefined&judgeStatus=undefined&tags=&title=
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 str = ""; while ((line = await readline())) { for (const i of line) { let code = i.charCodeAt(0); //转换为ASCLL码 let trans; if (code >= 97 && code <= 122) { switch (code) { case 115: trans = 7; break; case 118: trans = 8; break; case 121: case 122: trans = 9; break; default: trans = parseInt((code % 97) / 3) + 2; break; } str = str.concat(trans.toString()); } else if (code >= 65 && code < 90) { trans = code + 33; //ascll码转为string类型 str = str.concat(String.fromCharCode(trans)); } else if (code === 90) { str = str.concat("a"); } else { str = str.concat(i); } } console.log(str); } })();