Advertisement
mirozspace

Untitled

Apr 6th, 2019
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.13 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.regex.Matcher;
  3. import java.util.regex.Pattern;
  4.  
  5. public class Deciphering {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         String encryptedString = scanner.nextLine();
  9.  
  10.         StringBuilder sb = new StringBuilder();
  11.         for (int j = 0; j < encryptedString.length(); j++) {
  12.             char symbol = encryptedString.charAt(j);
  13.             symbol = (char) (symbol - 3);
  14.             sb.append(symbol);
  15.         }
  16.         encryptedString = sb.toString();
  17.  
  18.         String[] arrLine = scanner.nextLine().split("\\s+");
  19.         String searchedString = arrLine[0];
  20.         String newString = arrLine[1];
  21.  
  22.         String result = encryptedString.replaceAll(searchedString, newString);
  23.         String regex = "^[a-z ]+((?<=d)[a-z \\{\\}\\|\\#]+)*$";
  24.         Pattern pattern = Pattern.compile(regex);
  25.         Matcher matcher = pattern.matcher(result);
  26.  
  27.         if (matcher.find()) {
  28.             System.out.println(result);
  29.         } else {
  30.             System.out.println("This is not the book you are looking for.");
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement