mattnguyen

My Retake Final Exam 11/04/2022 Problem 2

Apr 11th, 2022
1,192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.25 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. namespace ConsoleApp10
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string regexPattern = @"(U\$)([A-Z][a-z]{2,})\1(P@\S)([A-z]{5,}[\d]+)\3";
  11.             int lines = int.Parse(Console.ReadLine());
  12.             int successfulRegistrationsCount = 0;
  13.  
  14.             for (int i = 0; i < lines; i++)
  15.             {
  16.                 string text = Console.ReadLine();
  17.  
  18.                 if (Regex.IsMatch(text, regexPattern))
  19.                 {
  20.                     successfulRegistrationsCount++;
  21.                     var match = Regex.Match(text, regexPattern);
  22.                     var splitted = match.ToString()
  23.                     .Split(new string[] { "U$", "P@$" }, StringSplitOptions.RemoveEmptyEntries);
  24.                     Console.WriteLine($"Registration was successful");
  25.                     Console.WriteLine($"Username: {splitted[0]}, Password: {splitted[1]}");
  26.                    
  27.                 }
  28.                 else
  29.                 {
  30.                     Console.WriteLine("Invalid username or password");
  31.                 }
  32.             }
  33.             Console.WriteLine($"Successful registrations: {successfulRegistrationsCount}");
  34.         }
  35.     }
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment