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 Deciphering {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String encryptedString = scanner.nextLine();
- StringBuilder sb = new StringBuilder();
- for (int j = 0; j < encryptedString.length(); j++) {
- char symbol = encryptedString.charAt(j);
- symbol = (char) (symbol - 3);
- sb.append(symbol);
- }
- encryptedString = sb.toString();
- String[] arrLine = scanner.nextLine().split("\\s+");
- String searchedString = arrLine[0];
- String newString = arrLine[1];
- String result = encryptedString.replaceAll(searchedString, newString);
- String regex = "^[a-z ]+((?<=d)[a-z \\{\\}\\|\\#]+)*$";
- Pattern pattern = Pattern.compile(regex);
- Matcher matcher = pattern.matcher(result);
- if (matcher.find()) {
- System.out.println(result);
- } else {
- System.out.println("This is not the book you are looking for.");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement