-
Notifications
You must be signed in to change notification settings - Fork 0
/
CamelCase pattern matching
55 lines (46 loc) · 1.37 KB
/
CamelCase pattern matching
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
//CamelCase pattern matching
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int t = Integer.parseInt(sc.nextLine());
while(t-- > 0) {
String[] arr = sc.nextLine().split(" ");
String pat = sc.nextLine();
Solution ob = new Solution();
List<String> ans = ob.camelCase(arr, pat);
if(ans.isEmpty()) {
System.out.println("[]");
}
else {
Collections.sort(ans);
System.out.println(String.join(" ", ans));
}
}
sc.close();
}
}
class Solution {
public List<String> camelCase(String[] arr, String pat) {
List<String> res = new ArrayList<>();
for(String word : arr) {
int i = 0, j = 0;
while(i < word.length() && j < pat.length()) {
if(Character.isLowerCase(word.charAt(i))) {
i++;
}
else if(word.charAt(i) != pat.charAt(j)) {
break;
}
else {
i++;
j++;
}
}
if(j == pat.length()) {
res.add(word);
}
}
return res;
}
}