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 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 grammars = new ArrayList<>(); private static List 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 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 grammars = new ArrayList<>(); private static List results = new ArrayList<>(); }