Advertisement
Guest User

Arriving in Kathamdnu

a guest
Dec 6th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. import java.util.Arrays;
  2. import java.util.Scanner;
  3. import java.util.regex.Matcher;
  4. import java.util.regex.Pattern;
  5.  
  6. public class ArrivinginKathmandu {
  7. public static void main(String[] args) {
  8. Scanner scanner = new Scanner(System.in);
  9.  
  10. Pattern pattern = Pattern.compile("^(?<name>[A-Za-z0-9!@#$?]+)=(?<number>\\d+)<<(?<geohashcode>.+)$");
  11. String input = scanner.nextLine();
  12. while (!input.equals("Last note")){
  13. Matcher matcher = pattern.matcher(input);
  14. if (matcher.find()) {
  15. String name = matcher.group("name");
  16. int number = Integer.parseInt(matcher.group("number"));
  17. String encrypted = matcher.group("geohashcode");
  18. if (number == encrypted.length()){
  19. name =name.replaceAll("[!@#$?]", "");
  20.  
  21. System.out.printf("Coordinates found! %s -> %s%n", name,encrypted);
  22. } else {
  23. System.out.println("Nothing found!");
  24. }
  25. }
  26. else {
  27. System.out.println("Nothing found!");
  28. }
  29. input = scanner.nextLine();
  30. }
  31. }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement