borovaneca

DestinationMapper

Apr 1st, 2023
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.01 KB | None | 0 0
  1. package WorldTour;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.IOException;
  5. import java.io.InputStreamReader;
  6. import java.util.ArrayList;
  7. import java.util.List;
  8. import java.util.regex.Matcher;
  9. import java.util.regex.Pattern;
  10.  
  11. public class DestinationMapper {
  12.     public static void main(String[] args) throws IOException {
  13.         BufferedReader scanner = new BufferedReader(new InputStreamReader(System.in));
  14.  
  15.  
  16.         String regex = "(\\=|\\/)(?<word>[A-Z][A-Za-z]{2,})(\\1)";
  17.         Pattern pattern = Pattern.compile(regex);
  18.         String input = scanner.readLine();
  19.         List<String> destinations = new ArrayList<>();
  20.         int sum = 0;
  21.         Matcher matcher = pattern.matcher(input);
  22.         while (matcher.find()) {
  23.             destinations.add(matcher.group("word"));
  24.             sum += destinations.get(destinations.size() - 1).length();
  25.         }
  26.         System.out.println("Destinations: " + String.join(", ", destinations));
  27.         System.out.println("Travel Points: " + sum);
  28.      }
  29. }
  30.  
Advertisement
Add Comment
Please, Sign In to add comment