题解 | #简单密码#

简单密码

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 () {
    // Write your code here
    rl.on("line", function (line) {
        let str = "";
        for (let i = 0; i < line.length; i++) {
            let s = line[i];
            if (/[a-z]/.test(s)) {
                if ("abc".includes(s)) {
                    str += "2";
                } else if ("def".includes(s)) {
                    str += "3";
                } else if ("ghi".includes(s)) {
                    str += "4";
                } else if ("jkl".includes(s)) {
                    str += "5";
                } else if ("mno".includes(s)) {
                    str += "6";
                } else if ("pqrs".includes(s)) {
                    str += "7";
                } else if ("tuv".includes(s)) {
                    str += "8";
                } else if ("wxyz".includes(s)) {
                    str += "9";
                }
            }else if(/[A-Z]/.test(s)){
                s=s.toLocaleLowerCase();
                s=s=='z'?'a':String.fromCharCode((s.charCodeAt()+1))
                str+=s
            }else if(/[0-9]/.test(s)){
                str+=s
            }
        }
        console.log(str)
    });
})();

全部评论

相关推荐

人间雪:简历最好只要一页,除非你牛逼到一页都写不下了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务