Advertisement
silvana1303

registration

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