Advertisement
Guest User

task 2

a guest
Dec 10th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 KB | None | 0 0
  1. package Exams.DemoFinalExam;
  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 Deciphering {
  10.     public static void main(String[] args) throws IOException {
  11.         BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  12.         String input = reader.readLine();
  13.         StringBuilder builder = new StringBuilder();
  14.         Pattern pattern = Pattern.compile("([d-z]+#?\\{?}?\\|?)+");
  15.         Matcher matcher = pattern.matcher(input);
  16.         if (!matcher.matches()) {
  17.             System.out.println("This is not the book you are looking for.");
  18.             return;
  19.         }
  20.         for (int i = 0; i < input.length(); i++) {
  21.             int curr = input.charAt(i);
  22.             /*
  23.             if (!(curr > 99 && curr < 126 || curr == 35 || curr == 32)){
  24.                 System.out.println("This is not the book you are looking for.");
  25.                 return;
  26.             }
  27.             */
  28.             int curr2 = input.charAt(i) - 3;
  29.             char current = (char) curr2;
  30.             builder.append(current);
  31.         }
  32.         input = reader.readLine();
  33.         String[] tokens = input.split(" ");
  34.         String text = builder.toString();
  35.         while (text.contains(tokens[0])) {
  36.             text = text.replace(tokens[0], tokens[1]);
  37.         }
  38.         System.out.println(text);
  39.  
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement