题解 | #字符串加密#

字符串加密

http://www.nowcoder.com/practice/e4af1fe682b54459b2a211df91a91cf3

let inputKey = readline();
let inputSec = readline().split("");
const allCha = "abcdefghijklmnopqrstuvwxyz"
inputKey = inputKey.concat(allCha);
let referCha = [];
referCha = [...new Set(inputKey)];
//console.log(referCha.join(""))
// A 65 ; a 97
let outputArr = [];
for(let i = 0; i < inputSec.length; i++){
    if (/[A-Z]/g.test(inputSec[i])){
        let idx =  inputSec[i].charCodeAt(0) -65;
        let temp = String.fromCharCode(referCha[idx].charCodeAt(0) -22);
        outputArr[i] = temp;
    }
        if (/[a-z]/g.test(inputSec[i])){
        let idx =  inputSec[i].charCodeAt(0) -97;
        let temp = String.fromCharCode(referCha[idx].charCodeAt(0));
        outputArr[i] = temp;
    }
    else if (/[^a-zA-Z]/g.test(inputSec[i])){
        outputArr[i] = inputSec[i];
    }
}
console.log(outputArr.join(""));
全部评论

相关推荐

迷茫的大四🐶:都收获五个了,兄弟那还说啥,不用改了,去玩吧
点赞 评论 收藏
分享
10-20 16:50
门头沟学院 Java
牛客68421677...:同是天涯沦落人啊,我也是26届0实习,不知道怎么办了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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