题解 | #字符串加密#

字符串加密

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(""));
全部评论

相关推荐

点赞 评论 收藏
分享
09-01 16:46
已编辑
门头沟学院 Java
mmvvpp:错了!!给了offer之后还有试用期,试用期过了就完事了?错了!还有每个季度的kpi考核,拿一个c就等着被劝退。那我好好干不拿c不就完了?错了!最多三年劳动合同到期,续不续期未知数。每年都有1800w毕业生毕业,今年你是小萌新蜜月期,明年你是老油条,长江后浪推前浪,前浪死在沙滩上。这就是——互联网!
秋招的破防瞬间
点赞 评论 收藏
分享
27双非本,最近面试被挂麻了面试官说简历内容太简单了,技术栈要单独一行,各位佬有啥建议吗
LZStarV:项目太简单了,你像用什么开发的技术栈没必要写一句话,按点写就好了;有特色的比如说WebSocket、视频流这种狠狠吹,那就好看多了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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