Advertisement
meteor4o

JF-Exams-TheIsleOfManTTRace

Aug 2nd, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.44 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4. import java.util.regex.Matcher;
  5. import java.util.regex.Pattern;
  6.  
  7. public class TheIsleOfManTTRace {
  8.     public static void main(String[] args) {
  9.         Scanner sc = new Scanner(System.in);
  10.  
  11.         String input = sc.nextLine();
  12.  
  13.         String regex = "([#$%*&])([A-Za-z]+)\\1(=)([0-9]+)!!(.*?)$";
  14.         Pattern pattern = Pattern.compile(regex);
  15.  
  16.         boolean match = false;
  17.  
  18.         while (!match) {
  19.             Matcher matcher = pattern.matcher(input);
  20.  
  21.             if (matcher.find()) {
  22.                 int length =  Integer.parseInt(matcher.group(4));
  23.                 String geocode = matcher.group(5);
  24.                 String name = matcher.group(2);
  25.  
  26.                 if  (geocode.length()!= length) {
  27.                     System.out.println("Nothing found!");
  28.  
  29.                 } else {
  30.                     match = true;
  31.                     String newCode = "";
  32.                     for (int i = 0; i < geocode.length(); i++) {
  33.                         char c = geocode.charAt(i);
  34.                         char newC = (char)(c+length);
  35.                         newCode += newC;
  36.                     }
  37.                     System.out.printf("Coordinates found! %s -> %s", name, newCode);
  38.                     return;
  39.                 }
  40.             } else {
  41.                 System.out.println("Nothing found!");
  42.             }
  43.             input = sc.nextLine();
  44.         }
  45.  
  46.     }
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement