Advertisement
Guest User

Valid Usernames

a guest
May 16th, 2015
460
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.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7.  
  8. namespace ValidUsernames
  9. {
  10.     class ValidUsernames // Alexander Anguelov
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             string input = Console.ReadLine();
  15.             string userName = @"\b\w{3,25}\b";
  16.             MatchCollection matches = Regex.Matches(input, userName);
  17.             List<string> valid = new List<string>();
  18.             foreach (var match in matches)
  19.             {
  20.                 if (char.IsLetter(match.ToString().First()))
  21.                 {
  22.                     valid.Add(match.ToString());
  23.                 }
  24.             }
  25.             int biggestSum = 0;
  26.             int pos = 0;
  27.             for (int i = 0; i < valid.Count - 1; i++)
  28.             {
  29.                 int currSum = valid[i].Length + valid[i + 1].Length;
  30.                 if (currSum > biggestSum)
  31.                 {
  32.                     biggestSum = currSum;
  33.                     pos = i;
  34.                 }
  35.             }
  36.             Console.WriteLine(valid[pos]);
  37.             Console.WriteLine(valid[pos + 1]);
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement