Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Hogwarts;
- import java.util.Map;
- import java.util.Scanner;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class EncryptingPassword {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- int n = Integer.parseInt(scanner.nextLine());
- String regex = "(\\S+)>(?<first>[\\d]{3})\\|(?<second>[a-z]{3})\\|(?<third>[A-Z]{3})\\|(?<fourth>[^><]{3})<(\\1)";
- Pattern pattern = Pattern.compile(regex);
- for (int i = 0; i < n; i++) {
- String text = scanner.nextLine();
- Matcher matcher = pattern.matcher(text);
- if (matcher.find()) {
- System.out.println("Password: " + matcher.group("first") + matcher.group("second") + matcher.group("third") + matcher.group("fourth"));
- } else {
- System.out.println("Try another password!");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment