-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathGa.java
More file actions
executable file
·78 lines (66 loc) · 1.67 KB
/
Copy pathGa.java
File metadata and controls
executable file
·78 lines (66 loc) · 1.67 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package string;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Ga {
static String str = "0#1#2#3#4#5#104#105#106#107";
public static void main(String[] args) {
// Ga.go(str, 107);
Ga.split();
//Ga.ttt();
}
static void split() {
String con = "{yahier is bingo,1989}";
Pattern p = Pattern.compile("yahier|1989");
Matcher m = p.matcher(con);
while (m.find()) {
String newCon = m.group();
System.out.println("newCon is " + newCon);
}
}
public static void ttt() {
String str = "no pains . no Gains.";
Pattern pattern = Pattern.compile("(\\w)*"); // [a-zA-Z_0-9]
Matcher matcher = pattern.matcher(str);
List<String> list = new ArrayList<String>();
int size = 0, length;
String temp;
String result = "";
while (matcher.find()) {
temp = matcher.group();
System.out.println("temp is "+temp);
list.add(temp);
length = temp.length();
if (length > size) {
size = length;
result = temp;
}
}
System.out.println(list);
System.out.println(result);
}
static void go(String str, int value) {
String[] strs = str.split("#");
StringBuffer sb = new StringBuffer();
boolean startExchange = false;
for (int i = 0; i < strs.length; i++) {
if (value == Integer.parseInt(strs[i])) {
startExchange = true;
}
if (startExchange) {
if (i + 1 < strs.length)
strs[i] = strs[i + 1];
}
}
for (int i = 0; i < strs.length - 1; i++) {
if (i != (strs.length - 2))
sb.append(strs[i] + "#");
else
sb.append(strs[i]);
}
System.out.println(Arrays.toString(strs));
System.out.println(sb.toString());
}
}