-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIntroduction.java
More file actions
61 lines (38 loc) · 1.17 KB
/
Introduction.java
File metadata and controls
61 lines (38 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
56
57
58
59
60
61
package intro;
import java.util.ArrayList;
public class Introduction {
static String decode(String pattern){
String Code="";
for(int i=0;i<pattern.length();i++){
int j=i+1;
char c1=pattern.charAt(i);
char c2 = pattern.charAt(j);
if(c1==c2){
Code=Code+".";
}else{
Code = Code+"-";
}
if(j==pattern.length()-1){
break;
}
}
return Code;
}
public static void main(String[] args) {
//sysout
String pattern ="foo";
String [] dict = {"abb" ,"abc" ,"xyz" ,"xyy"};
String Code=decode(pattern);
//String Code =decode(pattern);
ArrayList<String> result = new ArrayList<String>();
int l = dict.length;
for(int i=0;i<l;i++){
String newCode = decode(dict[i]);
System.out.println(newCode);
if(Code.equals(newCode)){
result.add(dict[i]);
}
}
System.out.println(result);
}
}