题解 | #简单密码#

简单密码

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
    const secrte = await readline();
    let res = ""
    const match = {
        '1': '1', 'a': '2', 'b': '2', 'c': '2',
        'd': '3', 'e': '3', 'f': '3','g': '4', 'h': '4', 'i': '4',
        'j': '5', 'k': '5', 'l': '5',
        'm': '6', 'n': '6', 'o': '6',
         'p': '7', 'q': '7', 'r': '7', 's': '7',
         't': '8', 'u': '8', 'v': '8',
        'w': '9', 'x': '9', 'y': '9', 'z': '9', '0': '0'
    };
  const keyMap = new Map(Object.entries(match))
    for (let i=0; i<secrte.length; i++) {
        if(keyMap.has(secrte[i])){
            res +=  keyMap.get(secrte[i])
        } else if( "A" <= secrte[i] && secrte[i] <= "Y") {
              res += String.fromCharCode(secrte[i].charCodeAt(0)+1).toLocaleLowerCase()
        } else if(secrte[i] == "Z") {
            res += "a"
        } else {
            res += secrte[i]
        }
    }
    console.log(res)
})();

全部评论

相关推荐

今天 12:17
已编辑
商丘师范学院 Java
后来123321:别着急,我学院本大二,投了1100份,两个面试,其中一个还是我去线下招聘会投的简历,有时候这东西也得看运气
无实习如何秋招上岸
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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