Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class _03_PostOfficce1 {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String[] message = scanner.nextLine().split("\\|");
- String first = message[0];
- String second = message[1];
- String third = message[2];
- String regFirstPart = "([$#%&*])([A-Z]+)(\\1)";
- Pattern p1st = Pattern.compile(regFirstPart);
- Matcher m1 = p1st.matcher(first);
- String firstLetters = "";
- if (m1.find()) {
- firstLetters = m1.group(2);
- }
- for (int i = 0; i < firstLetters.length(); i++) {
- char startLetter = firstLetters.charAt(i);
- int asciiCode = startLetter;
- String regSecondPart = "" + asciiCode + ":(?<length>[0-9]{2})";
- Pattern p2nd = Pattern.compile(regSecondPart);
- Matcher m2 = p2nd.matcher(second);
- int length = 0;
- if (m2.find()) {
- String l = m2.group("length").trim();
- length = Integer.parseInt(l);
- }
- String regThirdPart = "(?<=\\s|^)" + startLetter + "[\\S]{" + length + "}"+ "(?=\\s|$)";
- Pattern p3rd = Pattern.compile(regThirdPart);
- Matcher m3 = p3rd.matcher(third);
- if (m3.find()){
- String out = m3.group();
- System.out.println(out);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement