-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFollow
More file actions
157 lines (113 loc) · 4.11 KB
/
Follow
File metadata and controls
157 lines (113 loc) · 4.11 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
import java.io.*;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.Set;
public class Follow {
public static void main(String args[]) throws Exception {
FileReader fr = new FileReader("E:\\Work\\IntelliJ Idea Projects\\src\\InputFirst");
BufferedReader br = new BufferedReader(fr);
int noP = Integer.parseInt(br.readLine());
String sent[] = new String[noP];
for (int i = 0; i < noP; i++)
sent[i] = br.readLine();
String out[] = new String[noP+1];
out[noP]="~";
for (int i = 0; i < noP; i++) {
String s[] = sent[i].split("->");
String right = s[0];
String left = s[1];
//System.out.println("----------------\n"+" s[0] = "+right+" s[1] = "+left+"\n\n");
out[i] = right;
boolean t = true;
one:
while (Character.isUpperCase(left.charAt(0)) == true) {
t = false;
char fchar = left.charAt(0);
//System.out.println("fchar = "+fchar);
String temp[];
for (int j = 0; j < noP; j++) {
if (j != i) {
temp = sent[j].split("->");
if (temp[0].charAt(0) == fchar) {
//System.out.println("temp[0] here is : "+ temp[0]);
left = temp[1];
if (Character.isUpperCase(left.charAt(0))) {
//System.out.println("Jumpinh to while");
continue one;
}
else
out[i] += left.charAt(0);
}
}
}
}
if (t)
out[i] += left.charAt(0);
}
/*Arrays.sort(out);
for (String x : out)
System.out.println(x);
System.out.println("--------------------"); */
int strlen =0;
boolean f = false; String temp="";
for (int i = 0; i < noP; i++) {
if (f == false) {
//System.out.print(out[i].charAt(0) + " ");
f = true;
strlen++;
}
if (out[i].charAt(0) == out[i + 1].charAt(0));
//temp += out[i].substring(1) + out[i + 1].substring(1);
else if (out[i].charAt(0) != out[i + 1].charAt(0)) {
//temp += out[i].substring(1);
//System.out.print(remDup(temp) + "\n");
//temp="";
f = false;
}
}
String fir[] = new String[strlen];
strlen=-1;
f = false; temp="";
for (int i = 0; i < noP; i++) {
if (f == false) {
strlen++;
fir[strlen] = out[i].charAt(0) + " ";
f = true;
}
if (out[i].charAt(0) == out[i + 1].charAt(0))
temp += out[i].substring(1) + out[i + 1].substring(1);
else if (out[i].charAt(0) != out[i + 1].charAt(0)) {
temp += out[i].substring(1);
fir[strlen] = fir[strlen]+remDup(temp);
temp="";
f = false;
}
}
System.out.println("----------------------------");
for(String x : fir)
System.out.println(x);
// FOLLOW Calculations!
for(int i=0; i<strlen; i++){
char A = fir[i].charAt(0);
String t[];
for(int j=0; j<noP; j++){
t = sent[i].split("->");
if(t[1].indexOf('A')){
}
}
}
}
static String remDup(String x){
String string = x;
char[] chars = string.toCharArray();
Set<Character> charSet = new LinkedHashSet<Character>();
for (char c : chars) {
charSet.add(c);
}
StringBuilder sb = new StringBuilder();
for (Character character : charSet) {
sb.append(character);
}
return sb.toString();
}
}