emodev

Untitled

Dec 19th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.99 KB | None | 0 0
  1. package fund05Noem_2017_Part2;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.util.regex.Matcher;
  7. import java.util.regex.Pattern;
  8.  
  9. public class AnonymousVox {
  10.     public static void main(String[] args) throws IOException {
  11.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  12.  
  13.         String line = reader.readLine();
  14.         String placeholder = reader.readLine();
  15.         placeholder = placeholder.substring(1, placeholder.length() - 1);
  16.         String[] placeholders = placeholder.split("\\}\\{");
  17.  
  18.         Pattern pattern = Pattern.compile("([A-Za-z]+)(.*)(\\1)");
  19.         Matcher matcher = pattern.matcher(line);
  20.  
  21.         for (int i = 0; i < placeholders.length; i++) {
  22.             String replace = placeholders[i];
  23.             if (matcher.find()) {
  24.                 line = line.replace(matcher.group(2), replace);
  25.  
  26.             }
  27.         }
  28.         System.out.println(line);
  29.  
  30.     }
  31. }
Add Comment
Please, Sign In to add comment