题解 | #简单密码#

简单密码

https://www.nowcoder.com/practice/7960b5038a2142a18e27e4c733855dac

const rl = require("readline").createInterface({ input: process.stdin });
rl.on("line", (line) => {
    let newStr = "";
    let str = line;
    for (let i in str) {
        if (str[i] === "a" || str[i] === "b" || str[i] === "c") {
            newStr = newStr + "2";
        } else if (str[i] === "d" || str[i] === "e" || str[i] === "f") {
            newStr = newStr + "3";
        } else if (str[i] === "g" || str[i] === "h" || str[i] === "i") {
            newStr = newStr + "4";
        } else if (str[i] === "j" || str[i] === "k" || str[i] === "l") {
            newStr = newStr + "5";
        } else if (str[i] === "m" || str[i] === "n" || str[i] === "o") {
            newStr = newStr + "6";
        } else if (
            str[i] === "p" ||
            str[i] === "q" ||
            str[i] === "r" ||
            str[i] === "s"
        ) {
            newStr = newStr + "7";
        } else if (str[i] === "t" || str[i] === "u" || str[i] === "v") {
            newStr = newStr + "8";
        } else if (
            str[i] === "w" ||
            str[i] === "x" ||
            str[i] === "y" ||
            str[i] === "z"
        ) {
            newStr = newStr + "9";
        } else if (str[i] >= "A" && str[i] <= "Z") {
         if(str[i]==='Z'){
                        newStr=newStr+'a'
                    }else{
                        newStr = newStr + String.fromCharCode(str[i].charCodeAt() + 1).toLowerCase()
                    }
        } else {
            newStr = newStr + str[i];
        }
    }
    console.log(newStr);
});

全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务