题解 | #查找兄弟单词#
查找兄弟单词
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) {
let arr = line.split(" ");
const num = Number(arr[0]);
const x = arr[num + 1];
const sortedX = x.split("").sort().join("");
const index = arr[num + 2];
let words = arr.slice(1, num + 1);
let brothers = [];
function isBrother(word) {
if (word.length !== x.length || word === x) return false;
return word.split("").sort().join("") === sortedX;
}
words.forEach((w) => isBrother(w) && brothers.push(w));
brothers.sort();
console.log(brothers.length);
console.log(brothers[index-1]||'')
});
