题解 | #字符串加密#

字符串加密

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

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

// 原字母表
const arr = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u'
,'v', 'w', 'x', 'y', 'z']

const newArr = []
let num = 0
rl.on('line', function (line) {
    num++
    if(num == 1){
        // 新表头
        const buff = line.split('')
        for(let c of buff){
            if(!newArr.includes(c)) newArr.push(c)
        }
        
        // 把原字母表的字母,没出现过在新表头的放进新字母表中
        for(let c of arr){
            if(!newArr.includes(c)) newArr.push(c)
        }
    }else if(num === 2) {
        const cArr = line.split('')
        let res = ''
        for(let i = 0; i < cArr.length; i++){
            // 在原字母表找到该字母的下标
            const index = arr.findIndex((c)=>c === cArr[i])
            // 从新表取出对应的字母
            res += newArr[index]
        }
        console.log(res)
    }  
});

全部评论

相关推荐

这不纯纯作弊了吗😢😢😢
编程界菜鸡:信这个的这辈子有了,这智商你靠啥都没用
你找工作的时候用AI吗?
点赞 评论 收藏
分享
机械打工仔:有说的你怀疑一下就行了,直接问也太实诚了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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