Advertisement
ivanov_ivan

RegexMon

Nov 3rd, 2017
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.util.regex.Matcher;
  5. import java.util.regex.Pattern;
  6.  
  7. public class Regexmon {
  8.     public static void main(String[] args) throws IOException {
  9.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  10.  
  11.         String str = reader.readLine();
  12.  
  13.         Pattern bojoPat = Pattern.compile("[a-zA-Z]+-[a-zA-Z]+");
  14.         Pattern didiPat = Pattern.compile("[^a-zA-Z\\-]+");
  15.  
  16.         Matcher bojoMatch = bojoPat.matcher(str);
  17.         Matcher didiMatch = didiPat.matcher(str);
  18.  
  19.         int bojoIndex = 0;
  20.         int didiIndex = 0;
  21.  
  22.         while (true) {
  23.             boolean hasDMatch = false;
  24.             boolean hasBMatch = false;
  25.  
  26.             if (hasDMatch = didiMatch.find(didiIndex)) {
  27.                 bojoIndex = didiMatch.end();
  28.                 System.out.println(didiMatch.group());
  29.             }
  30.             if (!hasDMatch) break;
  31.  
  32.             if (hasBMatch = bojoMatch.find(bojoIndex)) {
  33.                 didiIndex = bojoMatch.end();
  34.                 System.out.println(bojoMatch.group());
  35.             }
  36.  
  37.             if (!hasBMatch) break;
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement