题解 | #简单密码#

简单密码

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

let str = readline();
let strArr = [...str];
let res = [];
for(let v of strArr) {
  //如果是大写字母
  if(/[A-Z]/.test(v)){
    if(v.toLowerCase() === 'z'){
      v = 'a';
    }else{
      v = v.toLowerCase().charCodeAt(0)+1*1;
      v = String.fromCharCode(v);
    }

    res.push(v);
  }else if(/[a-z]/.test(v)){//如果是小写字母
    if('abc'.split('').includes(v)){
      v = 2;
    }else if('def'.split('').includes(v)){
      v = 3;
    }else if('ghi'.split('').includes(v)){
      v = 4;
    }else if('jkl'.split('').includes(v)){
      v = 5;
    }else if('mno'.split('').includes(v)){
      v = 6;
    }else if('pqrs'.split('').includes(v)){
      v = 7;
    }else if('tuv'.split('').includes(v)){
      v = 8;
    }else if('wxyz'.split('').includes(v)){
      v = 9;
    }
    res.push(v);
  }else{
    res.push(v);
  }
}

console.log(res.join(''))
全部评论

相关推荐

点赞 评论 收藏
分享
双非坐过牢:非佬,可以啊10.28笔试,11.06评估11.11,11.12两面,11.19oc➕offer
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
11-27 10:46
点赞 评论 收藏
分享
评论
1
1
分享
牛客网
牛客企业服务