borovaneca

EncryptedPassword

Apr 3rd, 2023
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1. package Hogwarts;
  2.  
  3. import java.util.Map;
  4. import java.util.Scanner;
  5. import java.util.regex.Matcher;
  6. import java.util.regex.Pattern;
  7.  
  8. public class EncryptingPassword {
  9.     public static void main(String[] args) {
  10.         Scanner scanner = new Scanner(System.in);
  11.  
  12.  
  13.         int n = Integer.parseInt(scanner.nextLine());
  14.  
  15.         String regex = "(\\S+)>(?<first>[\\d]{3})\\|(?<second>[a-z]{3})\\|(?<third>[A-Z]{3})\\|(?<fourth>[^><]{3})<(\\1)";
  16.         Pattern pattern = Pattern.compile(regex);
  17.         for (int i = 0; i < n; i++) {
  18.             String text = scanner.nextLine();
  19.             Matcher matcher = pattern.matcher(text);
  20.             if (matcher.find()) {
  21.                 System.out.println("Password: " + matcher.group("first") + matcher.group("second") + matcher.group("third") + matcher.group("fourth"));
  22.             } else {
  23.                 System.out.println("Try another password!");
  24.             }
  25.  
  26.         }
  27.     }
  28. }
  29.  
Advertisement
Add Comment
Please, Sign In to add comment