Advertisement
Guest User

WeirdScript

a guest
Oct 26th, 2015
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.35 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 WeirdScript {
  6.     private static char getChar(int key) {
  7.  
  8.         if(key <= 52) {
  9.             if(key <= 26) {
  10.                 return (char) (key + 96);
  11.             }
  12.             return (char)(key + 38);
  13.         } else {
  14.             int division = key / 26;
  15.             return getChar(division % 2 == 0 ? key % 26: key % (26 * (division - 1)));
  16.         }
  17.     }
  18.     private static String getKey(int key) {
  19.         StringBuilder sb = new StringBuilder();
  20.         sb.append(getChar(key));
  21.         sb.append(getChar(key));
  22.         return sb.toString();
  23.  
  24.     }
  25.     public static void main(String[] args) {
  26.         Scanner sc = new Scanner(System.in);
  27.         String key = getKey(Integer.parseInt(sc.nextLine()));
  28.         StringBuilder sb = new StringBuilder();
  29.         String line = sc.nextLine();
  30.         while(!line.equals("End")) {
  31.             sb.append(line);
  32.             line = sc.nextLine();
  33.         }
  34.         String input = sb.toString();
  35.         Matcher matcher = Pattern.compile("(" + key + ")(.{0,50}?)(\\1)").matcher(input);
  36.         while(matcher.find()) {
  37.             String lineToPrint = matcher.group(2);
  38.             if(!lineToPrint.isEmpty()) {
  39.                 System.out.println(lineToPrint);
  40.             }
  41.  
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement