Advertisement
Guest User

Untitled

a guest
Dec 7th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. namespace _02._Registration
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             Regex regex = new Regex(@"^([U$].)([A-Z][a-z]+)(\1)([P@$]..)([A-z]{5,}[0-9]+)(\4)");
  11.  
  12.             int numberOfInputs = int.Parse(Console.ReadLine());
  13.  
  14.             int count = 0;
  15.  
  16.             for (int i = 0; i < numberOfInputs; i++)
  17.             {
  18.                 string input = Console.ReadLine();
  19.  
  20.                 Match match = regex.Match(input);
  21.  
  22.                 if (!match.Success)
  23.                 {
  24.                     Console.WriteLine("Invalid username or password");
  25.                 }
  26.                 else if (match.Success)
  27.                 {
  28.                     string username = match.Groups[2].Value;
  29.                     string password = match.Groups[5].Value;
  30.  
  31.                     count++;
  32.  
  33.                     Console.WriteLine("Registration was successful");
  34.                     Console.WriteLine($"Username: {username}, Password: {password}");
  35.                 }
  36.             }
  37.  
  38.             Console.WriteLine($"Successful registrations: {count}");
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement