SHARE
TWEET

SantasSecretHelper2

a guest Mar 24th, 2020 25 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2. import java.util.regex.Matcher;
  3. import java.util.regex.Pattern;
  4.  
  5. public class SantasSecretHelper {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         Pattern pattern = Pattern.compile("@([A-Za-z]+)[^@\\-!:>]*!([G])!");
  10.  
  11.         int key = Integer.parseInt(scanner.nextLine());
  12.  
  13.         String input;
  14.         while (!"end".equals(input = scanner.nextLine())) {
  15.             StringBuilder decrypted = new StringBuilder();
  16.  
  17.             for (int i = 0; i < input.length(); i++) {
  18.                 char symbol = (char) (input.charAt(i) - key);
  19.                 decrypted.append(symbol);
  20.             }
  21.             Matcher matcher = pattern.matcher(decrypted.toString());
  22.             if (matcher.find()) {
  23.                 String name = matcher.group(1);
  24.                 System.out.println(name);
  25.             }
  26.         }
  27.     }
  28. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top