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 WeirdScript {
- private static char getChar(int key) {
- if(key <= 52) {
- if(key <= 26) {
- return (char) (key + 96);
- }
- return (char)(key + 38);
- } else {
- int division = key / 26;
- return getChar(division % 2 == 0 ? key % 26: key % (26 * (division - 1)));
- }
- }
- private static String getKey(int key) {
- StringBuilder sb = new StringBuilder();
- sb.append(getChar(key));
- sb.append(getChar(key));
- return sb.toString();
- }
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String key = getKey(Integer.parseInt(sc.nextLine()));
- StringBuilder sb = new StringBuilder();
- String line = sc.nextLine();
- while(!line.equals("End")) {
- sb.append(line);
- line = sc.nextLine();
- }
- String input = sb.toString();
- Matcher matcher = Pattern.compile("(" + key + ")(.{0,50}?)(\\1)").matcher(input);
- while(matcher.find()) {
- String lineToPrint = matcher.group(2);
- if(!lineToPrint.isEmpty()) {
- System.out.println(lineToPrint);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement