Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class DestinationMapper {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String text = scanner.nextLine();
- String regex = "([\\=\\/]{1})(?<place>[A-Z][A-z]{2,})(\\1)";
- Pattern pattern = Pattern.compile(regex);
- Matcher matcher = pattern.matcher(text);
- List<String> location = new ArrayList<>();
- int points = 0;
- while (matcher.find()) {
- location.add(matcher.group("place"));
- points += matcher.group("place").length();
- }
- System.out.println("Destinations: " + String.join(", ", location));
- System.out.println("Travel Points: " + points);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement