Advertisement
CR7CR7

race

Dec 12th, 2022
602
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.14 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 TaskTwo {
  6.     public static void main(String[] args) {
  7.         Scanner scan =new Scanner(System.in);
  8.         String input = scan.nextLine();
  9.         String regex = "(\\#|\\$|\\%|\\*|\\&)(?<nameOfRacer>\\w+)\\1=(?<length>\\d+)!!(?<geohashcode>\\w+){5,}";
  10.         Pattern pattern = Pattern.compile(regex);
  11.         Matcher matcher = pattern.matcher(input);
  12.         StringBuilder sb =new StringBuilder();
  13.  
  14.         if(matcher.find()){
  15.             String geohashcode = matcher.group("geohashcode");
  16.             int length = Integer.parseInt(matcher.group("length"));
  17.             String nameOfRacer = matcher.group("nameOfRacer");
  18.  
  19.             for (int pos = 0; pos < geohashcode.length(); pos++) {
  20.                 char currentSymbol = input.charAt(pos);
  21.                 char decrypt = (char) (currentSymbol+length);
  22.                 sb.append(decrypt);
  23.             }
  24.  
  25.  
  26.  
  27.             System.out.printf("Coordinates found! %s -> %s",nameOfRacer,sb.toString());
  28.         }else{
  29.             System.out.println("Nothing found!");
  30.  
  31.         }
  32.     }
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement