-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConcepts.java
More file actions
55 lines (40 loc) · 1.17 KB
/
Concepts.java
File metadata and controls
55 lines (40 loc) · 1.17 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
import java.util.*;
public class Concepts{
public static void zig_zag(List<String> words, char[] queries)
{
System.out.println();
Collections.sort(words);
//Your Code goes here
String checked;
for(int j=0; j<queries.length; j++)
{
for(int i=0; i<words.size(); i++)
{
if(words.get(i).charAt(0)==queries[j])
{
System.out.println(words.get(i));
checked = words.remove(i);
i--;
words.add(checked);
break;
}
}
}
}
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
List<String> list = new ArrayList<>();
for(int i = 0; i < n; i++) {
list.add(s.next());
}
s.nextLine();
String str = s.nextLine();
String[] arr = str.split(" ");
char[] queries = new char[arr.length];
for(int i = 0; i < arr.length; i++) {
queries[i] = arr[i].charAt(0);
}
zig_zag(list, queries);
}
}