Advertisement
Daniel_007

02. Registration

Mar 25th, 2020
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.11 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. namespace Registration
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int howMany = int.Parse(Console.ReadLine());
  11.             int sumRegistration = 0;
  12.             for (int i = 0; i < howMany; i++)
  13.             {
  14.                 string input = Console.ReadLine();
  15.                 string pattern = @"U\$(?<username>[A-Z][a-z]{2,})U\$P@\$(?<password>[A-Za-z]{5,}\d+)P@\$";
  16.                 Match regisstration = Regex.Match(input, pattern);
  17.                 if (regisstration.Success)
  18.                 {
  19.                     Console.WriteLine("Registration was successful");
  20.                     Console.WriteLine($"Username: {regisstration.Groups["username"].Value}, Password: {regisstration.Groups["password"].Value}");
  21.                     sumRegistration++;
  22.                 }
  23.                 else
  24.                 {
  25.                     Console.WriteLine("Invalid username or password");
  26.                 }
  27.             }
  28.             Console.WriteLine($"Successful registrations: {sumRegistration}");
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement