Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class _01_Task {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String reg = "^(?<name>[a-zA-Z0-9!@#$?]+)=(?<length>[0-9]+)<<(?<code>.+)$";
- Pattern p = Pattern.compile(reg);
- String input = "";
- while(!"Last note".equals(input = sc.nextLine())){
- Matcher m = p.matcher(input);
- if (m.find()){
- String name = m.group("name");
- String len = m.group("length");
- int checkLength = Integer.parseInt(len);
- String checkCode = m.group("code");
- if(checkLength == checkCode.length()){
- StringBuilder sb = new StringBuilder();
- for (int i = 0; i < m.group("name").length(); i++) {
- if(Character.isLetterOrDigit(name.charAt(i))){
- sb.append(name.charAt(i));
- }
- }
- System.out.printf("Coordinates found! %s -> %s%n", sb, checkCode);
- }else{
- System.out.println("Nothing found!");
- }
- }else{
- System.out.println("Nothing found!");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement