Advertisement
Didart

Destination Mapper

Nov 28th, 2021
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.81 KB | None | 0 0
  1. import java.util.*;
  2. import java.util.regex.Matcher;
  3. import java.util.regex.Pattern;
  4.  
  5. public class DestinationMapper {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         String text = scanner.nextLine();
  10.  
  11.         String regex = "([\\=\\/]{1})(?<place>[A-Z][A-z]{2,})(\\1)";
  12.        
  13.         Pattern pattern = Pattern.compile(regex);
  14.         Matcher matcher = pattern.matcher(text);
  15.  
  16.         List<String> location = new ArrayList<>();
  17.  
  18.         int points = 0;
  19.         while (matcher.find()) {
  20.             location.add(matcher.group("place"));
  21.             points += matcher.group("place").length();
  22.         }
  23.         System.out.println("Destinations: " + String.join(", ", location));
  24.         System.out.println("Travel Points: " + points);
  25.     }
  26. }
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement