Advertisement
AngelKejov

Destination Mapper

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