题解 | #查找兄弟单词#
查找兄弟单词
https://www.nowcoder.com/practice/03ba8aeeef73400ca7a37a5f3370fe68
const rl = require("readline").createInterface({ input: process.stdin }); var iter = rl[Symbol.asyncIterator](); const readline = async () => (await iter.next()).value; //查找是不是兄弟元素 const isBro=(str1,str2)=>{ if(str1===str2)return false if(str1.split('').sort().join('')===str2.split('').sort().join(''))return true return false } void async function () { // Write your code here while(line = await readline()){ let tokens = line.split(' '); //提取数组数量 let num=Number(tokens.shift()) //提取数组 let arr=tokens.slice(0,num) //提取输出的兄弟数组的index let targetIndex=tokens.pop() //提取目标数组 let target=tokens.pop() let bro=[] //遍历数组,如果是兄弟数组就推入 for(let i=0;i<arr.length;i++){ if(isBro(target,arr[i])){ bro.push(arr[i]) } } console.log(bro.length); bro.sort() if(targetIndex>bro.length)return console.log(bro[targetIndex-1]) } }()