package com university import java io import java util import java uti

 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
package com.university;
import java.io.*;
import java.util.*;
import java.util.regex.*;
public class Main {
public static void init() throws IOException {
BufferedReader reader = new BufferedReader(new FileReader("./src/com/university/input.txt"));
String line;
while ((line = reader.readLine()) != null) {
grammars.add(line);
}
}
public static void gram(List<String> strings) {
Pattern pattern = Pattern.compile("([0-9a-z]+)([A-Z]*)([0-9a-z]+)$");
strings.forEach((str) -> {
String[] temp = str.split("\\::=");
for (int i = 0 ; i < 2; i++) {
Matcher matcher = pattern.matcher(temp[i]);
if (matcher.find())
for (int j = 1; j <= matcher.groupCount(); j++)
if (Character.isUpperCase(matcher.group(j).toCharArray()[0]))
for (char ch : matcher.group(j).toCharArray())
results.add("<1, " + ch + ">");
else
results.add("<0, " + matcher.group(j) + ">");
}
});
}
public static void main(String[] args) throws IOException {
init();
gram(grammars);
results.forEach(System.out::println);
}
private static List<String> grammars = new ArrayList<>();
private static List<String> results = new ArrayList<>();
}package com.university;
import java.io.*;
import java.util.*;
import java.util.regex.*;
public class Main {
public static void init() throws IOException {
BufferedReader reader = new BufferedReader(new FileReader("./src/com/university/input.txt"));
String line;
while ((line = reader.readLine()) != null) {
grammars.add(line);
}
}
public static void gram(List<String> strings) {
Pattern pattern = Pattern.compile("([0-9a-z]+)([A-Z]*)([0-9a-z]+)$");
strings.forEach((str) -> {
String[] temp = str.split("\\::=");
for (int i = 0 ; i < 2; i++) {
Matcher matcher = pattern.matcher(temp[i]);
if (matcher.find())
for (int j = 1; j <= matcher.groupCount(); j++)
if (Character.isUpperCase(matcher.group(j).toCharArray()[0]))
for (char ch : matcher.group(j).toCharArray())
results.add("<1, " + ch + ">");
else
results.add("<0, " + matcher.group(j) + ">");
}
});
}
public static void main(String[] args) throws IOException {
init();
gram(grammars);
results.forEach(System.out::println);
}
private static List<String> grammars = new ArrayList<>();
private static List<String> results = new ArrayList<>();
}