题解 | 查找兄弟单词

const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;

void (async function () {
    // Write your code here
    const line = await readline();
    const arr = line.split(" ");
    const X = arr[arr.length - 2];
    const XSort = X.split("").sort().join("");
    const res = [];
    for (let i = 0; i <= arr.length - 3; i++) {
        XLength = X.length;
        if (arr[i].length == XLength) {
            if (arr[i] !== X) {
                const nCur = arr[i].split("").sort().join("");
                if (nCur == XSort) {
                    // console.log("n", arr[i]);
                    res.push(arr[i]);
                }
            }
        }
    }
    console.log(res.length);
    if (arr[arr.length - 1] <= res.length) {
       res.sort()
       console.log(res[arr[arr.length - 1]-1])
    }
    
})();

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务