题解 | #查找兄弟单词#
查找兄弟单词
https://www.nowcoder.com/practice/03ba8aeeef73400ca7a37a5f3370fe68
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
// 注意 hasNext 和 hasNextLine 的区别
// while (in.hasNextInt()) { // 注意 while 处理多个 case
// int a = in.nextInt();
// int b = in.nextInt();
// System.out.println(a + b);
// }
int len = in.nextInt();
String[] arr = new String[len];
for (int i = 0; i < len; i++) {
arr[i] = in.next();
}
String word = in.next();
char[] wordChar = word.toCharArray();
Arrays.sort(wordChar);
int index = in.nextInt();
String k = "";
int count = 0;
Arrays.sort(arr);
for (int i = 0; i < len; i++) {
String str = arr[i];
char[] strChar = str.toCharArray();
Arrays.sort(strChar);
if (!Arrays.equals(wordChar, strChar)) {
continue;
}
if (word.equals(str)) {
continue;
}
count++;
if (count == index) {
k = str;
}
}
System.out.println(count);
System.out.print(k);
}
}

