-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCamelCase Pattern Matching.java
More file actions
49 lines (44 loc) · 1.37 KB
/
CamelCase Pattern Matching.java
File metadata and controls
49 lines (44 loc) · 1.37 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
//{ Driver Code Starts
//Initial Template for Java
import java.io.*;
import java.util.*;
class GFG {
public static void main(String args[]) throws IOException {
BufferedReader read =
new BufferedReader(new InputStreamReader(System.in));
int t = Integer.parseInt(read.readLine());
while (t-- > 0) {
int N = Integer.parseInt(read.readLine());
String[] Dictionary=read.readLine().split(" ");
String Pattern=read.readLine();
Solution ob = new Solution();
ArrayList <String> ans=ob.CamelCase(N,Dictionary,Pattern);
for(String u:ans)
System.out.print(u+" ");
System.out.println();
}
}
}
// } Driver Code Ends
//User function Template for Java
class Solution{
ArrayList<String> CamelCase(int N,String[] Dictionary,String Pattern){
//code here
ArrayList<String> ans=new ArrayList<>();
for(String s: Dictionary)
{
String str="";
for(char c:s.toCharArray())
{
if(Character.isUpperCase(c))
str+=c;
}
if(str.length()>=Pattern.length() && str.substring(0,Pattern.length()).equals(Pattern))
ans.add(s);
}
if(ans.size()==0)
ans.add("-1");
Collections.sort(ans);
return ans;
}
}