-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathFunction.java
More file actions
104 lines (90 loc) · 3.59 KB
/
Copy pathFunction.java
File metadata and controls
104 lines (90 loc) · 3.59 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
99
100
101
102
103
104
package keyWordSubString;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
public class Function
{
public static void main(String[] args)
{
try {
System.out.println("请输入包含M个单词的英文描述,用空格隔开:");
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
inputData = in.readLine();
} catch (IOException e) {
// TODO Auto-generated catch block
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) {
// TODO Auto-generated catch block
System.out.println("IOException:" + e.getMessage());
}
// System.out.println("-----------------------------------");
String[] inputDataArray = inputData.split(" ");
String[] inputKeyWordsArray = inputKeyWords.split(" ");
int dataLength = inputDataArray.length;
int keyWordsLength = inputKeyWordsArray.length;
// System.out.println("////////////////////////////////////////////////////");
// System.out.println("dataLength = " + dataLength + "; keyWordsLength = " + keyWordsLength);
Comparator comparator = new Comparator();
comparator.setStr(inputKeyWordsArray);
int startIndex = 0;
int endIndex = 0;
for(int index = 0;index<dataLength;index++)
{
if(indexList.size() >= keyWordsLength){
break;
}else if(comparator.equaledWith(inputDataArray[index])){
if(indexList.isEmpty()){
// System.out.println("inputDataArray[index] = " + inputDataArray[index]+"/"+index);
indexList.add(inputDataArray[index]+ "/" + index);
}else{
elementOperationInList.setTargetList(indexList);
// System.out.println("inputDataArray[index] = " + inputDataArray[index]+"/"+index);
tempIndex = elementOperationInList.getElementFromList(inputDataArray[index]+"/"+index);
// System.out.println("/////////////////////////////////////////////");
// System.out.println("tempIndex = " + tempIndex);
// for(String obj:indexList)
// {
// System.out.println(obj);
// }
// System.out.println("tempIndex = " + tempIndex);
if(tempIndex > 1){
indexList.remove(tempIndex - 1);
indexList.add(inputDataArray[index] + "/" + index);
}else{
indexList.add(inputDataArray[index] + "/" + index);
}
}
}
}
// System.out.println("/////////////////////////////////////////////");
// for(String obj:indexList)
// {
// System.out.println(obj);
// }
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);
}
private static ArrayList<String> indexList = new ArrayList<String>();
private static int tempIndex;
private static ElementOperationInList elementOperationInList = new ElementOperationInList();
private static int startIndex = 0;
private static int endIndex = 0;
private static String inputData = "";
private static String inputKeyWords = "";
}