-
Notifications
You must be signed in to change notification settings - Fork 111
Expand file tree
/
Copy pathLeftRecursion.java
More file actions
45 lines (40 loc) · 1.35 KB
/
Copy pathLeftRecursion.java
File metadata and controls
45 lines (40 loc) · 1.35 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
package left_recursion;
import java.util.*;
import java.io.*;
public class LeftRecursion {
private static ArrayList<String> data = new ArrayList<>();
private static ArrayList<String> dataLine = new ArrayList<>();
private static void getData() throws IOException{ // Получение данных
FileReader file = new FileReader("input.txt");
Scanner sc = new Scanner(file);
while (sc.hasNextLine()){
dataLine.add(sc.nextLine());
}
for(int i = 0; i < dataLine.size(); i++){
if(i != 0){
StringTokenizer st = new StringTokenizer(dataLine.get(i), "->");
while (st.hasMoreTokens()){
data.add(st.nextToken());
}
}
}
}
public static void main(String[] argv) throws IOException{
getData();
int count = 0;
String left = "";
for(int i = 0; i < data.size(); i++){
if(i % 2 == 0){
left = data.get(i);
}else{
char oneSymbolRight = data.get(i).charAt(0);
if(left.equals(String.valueOf(oneSymbolRight))){
count++;
}
}
}
PrintWriter pw = new PrintWriter(new File("output.txt"));
pw.print(String.valueOf(count));
pw.close();
}
}