题解 | #简单密码#

简单密码

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-09 01:22
已编辑
东南大学 Java
高级特工穿山甲:羡慕,我秋招有家企业在茶馆组织线下面试,约我过去“喝茶详谈”😢结果我去了发现原来是人家喝茶我看着
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务