Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package a4_FINAL_EXAM_14March2019;
- import java.util.Scanner;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class P1_TheIsleOfManRace_gr2 {
- public static void main(String[] args) {
- @SuppressWarnings("resource")
- Scanner sc = new Scanner(System.in);
- boolean isFound = false;
- while (!isFound) {
- String line = sc.nextLine();
- String regex = "([$#%*&])(?<name>[A-Za-z]+)\\1=(?<length>[\\d]+)!!(?<geohash>.+)";
- Pattern pattern = Pattern.compile(regex);
- Matcher matcher = pattern.matcher(line);
- if (matcher.find()) {
- String name = matcher.group("name");
- int length = Integer.parseInt(matcher.group("length"));
- String geohash = matcher.group("geohash");
- if (length == geohash.length()) {
- isFound = true;
- String geohashCode = "";
- for (int i = 0; i < geohash.length(); i++) {
- char symbol = geohash.charAt(i);
- geohashCode += (char)(symbol + geohash.length());
- }
- System.out.println(String.format("Coordinates found! %s -> %s", name, geohashCode));
- isFound = true;
- } else {
- isFound = false;
- System.out.println("Nothing found!");
- }
- } else {
- isFound = false;
- System.out.println("Nothing found!");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment