-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearch_1.java
More file actions
66 lines (56 loc) · 1.68 KB
/
Copy pathSearch_1.java
File metadata and controls
66 lines (56 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package HuaweiCoding;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.Scanner;
public class Search_1 {
public static void getBrotherWord(int counts,String[] words,String key,int num) {
ArrayList<String> storedList=new ArrayList<>();
LinkedList<String> linkedList=new LinkedList<>();
for (String word : words) {
linkedList.add(word);
}
ArrayList<Character> arrayList=new ArrayList<>();
for(int i=0;i<key.length();i++) {
arrayList.add(key.charAt(i));
}
Collections.sort(arrayList);
int totals=0;
for (String itemValue : linkedList) {
if(itemValue.length()==key.length() && !itemValue.equals(key)) {
ArrayList<Character> arrayList2=new ArrayList<>();
for(int i=0;i<itemValue.length();i++) {
arrayList2.add(itemValue.charAt(i));
}
Collections.sort(arrayList2);
if(arrayList.equals(arrayList2)) {
totals++;
storedList.add(itemValue);
}
}
}
Collections.sort(storedList,new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
// TODO Auto-generated method stub
return o1.toLowerCase().compareTo(o2.toLowerCase());
}
});
System.out.println(totals);
System.out.println(storedList.get(num-1));
}
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
while(sc.hasNext()) {
int counts = sc.nextInt();
String[] words=new String[counts];
for(int i=0;i<counts;i++) {
words[i]=sc.next();
}
String key=sc.next();
int num=sc.nextInt();
getBrotherWord(counts, words, key, num);
}
}
}