知识点

String相关

fromCharCode()
toLowerCase()
charCodeAt()
includes() \

Map对象

存储

正则

^ 开始符

$ 结束符

/^[0-9]$/  匹配数字

使用正则表达式

let arr =  readline().split('')
let len = arr.length
let res = ''
const map = {
    'abc' : '2', 'def':'3', 'ghi':'4', 'jkl':'5', 'mno':'6', 'pqrs':'7', 'tuv':'8', 'wxyz':'9'
}
for(let i = 0; i< len; i++){
   if(/^[A-Z]$/.test(arr[i])){
       if(arr[i]==='Z'){
           res += 'a'
       } else {
           res += String.fromCharCode(arr[i].toLowerCase().charCodeAt() + 1)
       }
       continue
   }
    if(/^[a-z]$/.test(arr[i])){
        for(let item in map){
            if(item.includes(arr[i])){
                res += map[item]
            }
        }
        continue
    }
    if(/^[0-9]$/.test(arr[i])){
        res += arr[i]
        continue
    }
}
print(res)

傻瓜式解法

let n = readline()
let arr = n.split('')
let len = arr.length
for(let i = 0; i< len; i++){
    if(arr[i].charCodeAt()>=64 &&arr[i].charCodeAt() <90){
      let trans =  String.fromCharCode(arr[i].charCodeAt() + 33)
      arr[i] = trans
    } else if(arr[i].charCodeAt()==90){
       arr[i] = 'a'
    } else { 
        if(arr[i] == 'a' || arr[i] == 'b' || arr[i] == 'c'){
            arr[i]=2
        }
        if(arr[i] == 'd' || arr[i] == 'e' || arr[i] == 'f'){
            arr[i]=3
        }
        if(arr[i] == 'g' || arr[i] == 'h' || arr[i] == 'i'){
            arr[i]=4
        }
        if(arr[i] == 'j' || arr[i] == 'k' || arr[i] == 'l'){
            arr[i]=5
        }
         if(arr[i] == 'm' || arr[i] == 'n' || arr[i] == 'o'){
            arr[i]=6
        }
         if(arr[i] == 'p' || arr[i] == 'q' || arr[i] == 'r' || arr[i] == 's'){
            arr[i]=7
        }
         if(arr[i] == 'w' || arr[i] == 'x' || arr[i] == 'y' || arr[i] == 'z'){
            arr[i]=9
        }
         if(arr[i] == 't' || arr[i] == 'u' || arr[i] == 'v'){
            arr[i]=8
        }
    }
}
print(arr.join(''))