Advertisement
Guest User

Valid usernames

a guest
Oct 26th, 2016
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7.  
  8. public class Ex
  9. {
  10. public static void Main()
  11. {
  12. string text = Console.ReadLine();
  13. string pattern = @"(?:^|\W)([a-z][\w]{2,24})";
  14. Regex regex = new Regex(pattern);
  15. MatchCollection matches = regex.Matches(text);
  16.  
  17. int len = 0;
  18. int maxLen = int.MinValue;
  19. string firstUsername = "";
  20. string secondUsername = "";
  21.  
  22. for (int i = 0; i < matches.Count - 1; i++)
  23. {
  24. len = matches[i].Groups[1].Length + matches[i + 1].Groups[1].Length;
  25.  
  26. if (len > maxLen)
  27. {
  28. maxLen = len;
  29. firstUsername = matches[i].Groups[1].ToString();
  30. secondUsername = matches[i + 1].Groups[1].ToString();
  31. }
  32. }
  33.  
  34. Console.WriteLine(firstUsername);
  35. Console.WriteLine(secondUsername);
  36. }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement