Advertisement
mimi_em

ValidUsernames

Jun 3rd, 2016
748
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. namespace _07.ValidUsernames
  2. {
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Text.RegularExpressions;
  6.  
  7. class Startup
  8. {
  9. static void Main()
  10. {
  11. string line = Console.ReadLine();
  12. string splitter = @"\W+";
  13. string[] usernames = Regex.Replace(line, splitter, " ").Split(new char[]{ ' ' },StringSplitOptions.RemoveEmptyEntries);
  14. string pattern = @"^[a-zA-Z][a-zA-Z0-9_]{2,24}$";
  15. Regex regex = new Regex(pattern);
  16. List <string> valid = new List<string>();
  17.  
  18. foreach (var item in usernames)
  19. {
  20. if (regex.IsMatch(item))
  21. {
  22. valid.Add(item);
  23. }
  24. }
  25.  
  26. int sumMax = 0;
  27. string first = String.Empty;
  28. string second = String.Empty;
  29.  
  30. for (int i = 1; i < valid.Count; i++)
  31. {
  32. int currentSum = valid[i - 1].Length + valid[i].Length;
  33. if (currentSum > sumMax)
  34. {
  35. sumMax = currentSum;
  36. first = valid[i - 1];
  37. second = valid[i];
  38. }
  39. }
  40. Console.WriteLine(first);
  41. Console.WriteLine(second);
  42. }
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement