题解 | #查找兄弟单词#

查找兄弟单词

https://www.nowcoder.com/practice/03ba8aeeef73400ca7a37a5f3370fe68

const readline = require('readline');

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
rl.on('line', function (line) {
    const tokens = line.split(' ');
    const n = Number(tokens[0])
    const arr = tokens.slice(1, n+1)
    const word = tokens.at(-2)
    const k = Number(tokens.at(-1))

    const res = []

    for(let str of arr){
        if(str !== word && str.split('').sort().join('') === word.split('').sort().join('')){
            res.push(str)
        }
    }

    console.log(res.sort().length)
    console.log(res[k-1] ?? '')
})

全部评论

相关推荐

测试糕手手:社会第一课,随便吹牛逼,直接说四个月,别老实。老实人只会被欺负
点赞 评论 收藏
分享
06-11 17:39
门头沟学院 Java
小呆呆的大鼻涕:卧槽,用户彻底怒了
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
昨天 11:15
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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