题解 | #简单密码#

简单密码

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);
    }
})();

全部评论

相关推荐

点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
11-20 19:57
已编辑
某大厂 golang工程师 23.0k*16.0, 2k房补,年终大概率能拿到
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务