题解 | #查找兄弟单词#
查找兄弟单词
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;
void async function () {
let line= (await readline()).split(' ');
let arr=line.slice(1,line.length-2);
let word=line[line.length-2]
let k=line[line.length-1]
let num=0;
let res=[];
for(let i=0;i<arr.length;i++){
if(simiword(arr[i],word)){
num++;
res.push(arr[i])
}
}
res.sort();
console.log(num);
if(num!=0 && res[k-1]){
console.log(res[k-1]);
}
}()
function simiword(unKnowWord,word){
if(unKnowWord==word){
return 0;
}
let unKnowWord1=unKnowWord.split('');
let word1=word.split('');
if(unKnowWord1.length != word1.length){
return 0;
}
for(let i=0;i<word1.length;i++){
unKnowWord=unKnowWord.replace(word1[i],'');
}
if(unKnowWord != ''){
return 0;
}
return 1;
}
function simiword(unKnowWord, word) {
if (unKnowWord == word) {
return 0;
}
unKnowWord = unKnowWord.split('').sort().join('');
word = word.split('').sort().join('');
if (unKnowWord == word) {
return 1;
} else {
return 0;
}
}
