题解 | #字符串加密#

字符串加密

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

//先去重获得秘钥然后进行二次去重获取字典,使用asc码差值获取字母位置
while(key = readline()) {
    const newStr =  Array.from(new Set(key.split(''))).join('').toLowerCase();
    const book = newStr + 'abcdefghijklmnopqrstuvwxyz';
    const bookList = Array.from(new Set(book.split('')));
    
    const passStr = readline().split('');
    let result = [];
    for (let char of passStr) {
        let code = char.charCodeAt();
        if (code >=65 && code <= 90) {
            let index = code - 65;
            let str = bookList[index].toUpperCase();
            result.push(str);
        } else if (code >=97 && code <= 122) {
            let index = code - 97;
            result.push(bookList[index]);
        } else {
            let str = String.fromCharCode(code);
            result.push(str);
        }
    }
    print(result.join(''));
}
全部评论

相关推荐

码农索隆:想看offer细节
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
06-29 17:30
找实习找着找着就要进入7月了,马上秋招也要开始了,找实习还有意义吗?
绝迹的星:有面就面, 没面上就当日薪4位数大佬免费培训, 面上了再考虑要不要实习
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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