Advertisement
Guest User

Valid usernames

a guest
Feb 18th, 2017
539
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 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. namespace _12.Valid_Usernames
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. string text = Console.ReadLine();
  15. string pattern = @"\b[a-zA-Z][a-zA-Z0-9_]{2,24}\b";
  16. Regex regex = new Regex(pattern);
  17. MatchCollection matchCollection = regex.Matches(text);
  18. var list = new List<string>();
  19.  
  20. int sum = 0;
  21. int maxSum = 0;
  22. string first = "";
  23. string second = "";
  24.  
  25.  
  26. for (int i = 1; i < matchCollection.Count; i++)
  27. {
  28. sum = matchCollection[i - 1].Length+ matchCollection[i].Length;
  29.  
  30. if (sum>maxSum)
  31. {
  32. maxSum = sum;
  33. first = matchCollection[i - 1].ToString();
  34. second = matchCollection[i].ToString();
  35.  
  36. }
  37. }
  38.  
  39. Console.WriteLine(first);
  40. Console.WriteLine(second);
  41.  
  42.  
  43. }
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement