-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathWildcards.java
More file actions
64 lines (51 loc) · 1.91 KB
/
Copy pathWildcards.java
File metadata and controls
64 lines (51 loc) · 1.91 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
import java.util.*;
import java.io.*;
class Main {
public static boolean StringChallenge(String str) {
// code goes here
String[] strArr= str.split(" ");
String myStr =strArr[1];
List<String> myList = new ArrayList<String>();
List<String> newList = new ArrayList<String>();
List<String> otherList = new ArrayList<String>();
int j=0;
for (int i = 1; i < myStr.length() ; i++) {
if (myStr.charAt(i - 1) != myStr.charAt(i)) {
myList.add(myStr.substring(j, i));
j = i;
}
}
myList.add(myStr.substring(j));
System.out.println(myList);
for(String i: myList){
if(i.matches("[0-9]")){
newList.add("$");
otherList.add("$");
}
else if(i.length()==1){
newList.add("+");
otherList.add("*{1}");
}
else if(i.length()!=3){
newList.add("*{"+String.valueOf(i.length())+"}");
otherList.add("*{"+String.valueOf(i.length())+"}");
}
else if(i.length()==3) {
newList.add("*");
otherList.add("*");
}
}
String result=newList.toString().replace("[","").replace("]","").replaceAll(",","").replaceAll(" ","");
String result1=otherList.toString().replace("[","").replace("]","").replaceAll(",","").replaceAll(" ","");
System.out.println(result);
if(result.equals(strArr[0])||result1.equals(strArr[0])){
return true;
}
return false;
}
public static void main (String[] args) {
// keep this function call here
Scanner s = new Scanner(System.in);
System.out.print(StringChallenge(s.nextLine()));
}
}