Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class TheIsleOfManTTRace {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String input = sc.nextLine();
- String regex = "([#$%*&])([A-Za-z]+)\\1(=)([0-9]+)!!(.*?)$";
- Pattern pattern = Pattern.compile(regex);
- boolean match = false;
- while (!match) {
- Matcher matcher = pattern.matcher(input);
- if (matcher.find()) {
- int length = Integer.parseInt(matcher.group(4));
- String geocode = matcher.group(5);
- String name = matcher.group(2);
- if (geocode.length()!= length) {
- System.out.println("Nothing found!");
- } else {
- match = true;
- String newCode = "";
- for (int i = 0; i < geocode.length(); i++) {
- char c = geocode.charAt(i);
- char newC = (char)(c+length);
- newCode += newC;
- }
- System.out.printf("Coordinates found! %s -> %s", name, newCode);
- return;
- }
- } else {
- System.out.println("Nothing found!");
- }
- input = sc.nextLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement