题解 | #简单密码#

简单密码

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

全部评论

相关推荐

点赞 评论 收藏
分享
昨天 13:37
重庆大学 C++
点赞 评论 收藏
分享
程序员小白条:太晚了,看别人找到实习了才投的话,自己本身就没啥准备,计划太晚咯,只能吞苦果子
点赞 评论 收藏
分享
真起不了响亮的名字:九月份人家投秋招你投实习嘛,会不会有点晚了,算你九月份直接上岗,实习三个月后一月初去和别人抢秋招补录还是备战春招啊更别说休息一个月后还要重新复习八股和算法
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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