Advertisement
Kur23

asfga

Aug 14th, 2021
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.99 KB | None | 0 0
  1. package PodgotovkaZaIzpit2;
  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.     public static void main(String[] args) {
  11.         Scanner scanner = new Scanner(System.in);
  12.         String regex = "(?<separator>[/=])(?<destination>[A-Z][A-Za-z]{2,})\\1";
  13.         String input = scanner.nextLine();
  14.  
  15.         Pattern pattern = Pattern.compile(regex);
  16.         Matcher matcher = pattern.matcher(input);
  17.  
  18.         List<String> destinations = new ArrayList<>();
  19.  
  20.         while (matcher.find()){
  21.             destinations.add(matcher.group("destination"));
  22.         }
  23.         int travelPoints;
  24.         travelPoints = destinations.stream().mapToInt(String::length).sum();
  25.  
  26.         String resultText = String.join(", ", destinations);
  27.  
  28.         System.out.printf("Destination: %s%n", resultText);
  29.         System.out.printf("Travel Points: %d", travelPoints);
  30.     }
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement