forked from KeepMoving/AlgorithmsLibrary
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunction.java
More file actions
98 lines (86 loc) · 3.13 KB
/
Copy pathFunction.java
File metadata and controls
98 lines (86 loc) · 3.13 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package keyWordSubString2nd;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import keyWordSubString.ElementOperationInList;
public class Function
{
public static void main(String[] args)
{
String loop = "N";
do{
try {
System.out.println("请输入包含M个单词的英文描述,用空格隔开:");
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
inputData = in.readLine();
} catch (IOException e) {
System.out.println("IOException:" + e.getMessage());
}
System.out.println("-----------------------------------");
try {
System.out.println("请输入包含N个单词的英文关键词,用空格隔开:");
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
inputKeyWords = in.readLine();
} catch (IOException e) {
System.out.println("IOException:" + e.getMessage());
}
String[] inputDataArray = inputData.split(" ");
String[] inputKeyWordsArray = inputKeyWords.split(" ");
int keyWordsLength = inputKeyWordsArray.length;
int i = 0;
for(String targetword:inputDataArray)
{
if(indexList.size() >= keyWordsLength){
break;
}else{
for(String keyword:inputKeyWordsArray)
{
if(targetword.matches(keyword)){
if(indexList.isEmpty()){
indexList.add(inputDataArray[i]+ "/" + i);
}else{
elementOperationInList.setTargetList(indexList);
tempIndex = elementOperationInList.getElementFromList(inputDataArray[i]+"/"+i);
if(tempIndex >= 0){
System.out.println("删除的元素为:" + indexList.remove(tempIndex));
indexList.add(inputDataArray[i] + "/" + i);
}else{
indexList.add(inputDataArray[i] + "/" + i);
}
}
}
}
}
i++;
}
int startIndex = 0;
int endIndex = 0;
String[] startPoint = indexList.get(0).split("/");
String[] endPoint = indexList.get(keyWordsLength - 1).split("/");
startIndex = Integer.parseInt(startPoint[1]);
endIndex = Integer.parseInt(endPoint[1]);
String resultStr = "";
for(int index = startIndex;index <= endIndex;index++)
{
resultStr += inputDataArray[index] + " ";
}
System.out.println("---------------------------------------");
System.out.println("结果是:" + resultStr);
System.out.println("---------------------------------------");
System.out.println("继续吗?(Y/N)");
try {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
loop = in.readLine();
} catch (IOException e) {
System.out.println("IOException:" + e.getMessage());
}
}while(loop.endsWith("Y")|| loop.endsWith("y"));
System.out.println("游戏结束!");
}
private static ArrayList<String> indexList = new ArrayList<String>();
private static ElementOperationInList elementOperationInList = new ElementOperationInList();
private static int tempIndex;
private static String inputData = "";
private static String inputKeyWords = "";
}