1. 题目
读题
考查点
2. 解法
思路
代码逻辑
具体实现
public class HJ027 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String[] str = sc.nextLine().split("\\s+");
int n = Integer.valueOf(str[0]);
String[] array = new String[n];
for (int i = 1; i <= n; i++) {
array[i - 1] = str[i];
}
String word = str[n + 1];
int k = Integer.valueOf(str[n + 2]);
findBrotherWord(array, word, k);
}
public static void findBrotherWord(String[] array, String word, int k) {
List<String> list = new ArrayList<>();
for (String cur : array) {
if (isBrother(word, cur)) {
list.add(cur);
}
}
System.out.println(list.size());
Collections.sort(list);
System.out.println(list.get(k - 1));
}
public static boolean isBrother(String word, String curWord) {
if (word.length() != curWord.length() || word.equals(curWord)) {
return false;
}
for (char c : word.toCharArray()) {
if (curWord.indexOf(c) < 0) {
return false;
}
}
return true;
}
}