Untitled

mail@pastecode.io avatarunknown
plain_text
6 days ago
1.2 kB
2
Indexable
Never
package FinalTest;

import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Registration {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        Pattern regex = Pattern.compile("^U\\$(?<password>[A-Z][a-z]{2,})U\\$P@\\$(?<username>[A-Za-z]{5,}[0-9]+)P@\\$$");
        int counter = 0;


        for (int i = 0; i < n; i++) {
            String inputLine = sc.nextLine();
            Matcher matcher = regex.matcher(inputLine);
            if (matcher.find()) {
                System.out.println("");
                counter++;
                String username = matcher.group("password");
                String password = matcher.group("username");
                System.out.println("Registration was successful");
                System.out.printf("Username: %s, Password: %s\n", username, password);
            } else {
                System.out.println("Invalid username or password");
            }
        }
        System.out.printf("Successful registrations: %d", counter);
    }
}