Advertisement
Guest User

Untitled

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