Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.*;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- import java.util.stream.Collectors;
- public class Main {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String encrypted = scanner.nextLine();
- String afterEncryption = "";
- List<String> letters = Arrays
- .stream(scanner.nextLine()
- .split(" "))
- .collect(Collectors.toList());
- String regex = "^([d-z\\{\\}\\|#]+)";
- Pattern pattern = Pattern.compile(regex);
- Matcher matcher = pattern.matcher(encrypted);
- System.out.println();
- if (!matcher.find()){
- System.out.println("This is not the book you are looking for.");
- }else {
- for (int i = 0; i < encrypted.length(); i++) {
- afterEncryption += (char)((int)encrypted.charAt(i) - 3);
- }
- String first = letters.get(0);
- String second = letters.get(1);
- if (afterEncryption.contains(first)) {
- int index = afterEncryption.indexOf(first);
- while (index != -1) {
- afterEncryption = afterEncryption.replace(first, second);
- index = afterEncryption.indexOf(first);
- }
- }
- }
- System.out.println(String.join(" ",afterEncryption));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement