Skip to content

Instantly share code, notes, and snippets.

@aanguelov
Created May 16, 2015 07:15
Show Gist options
  • Save aanguelov/ab9c1d4c00da9130a686 to your computer and use it in GitHub Desktop.
Save aanguelov/ab9c1d4c00da9130a686 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
namespace ValidUsernames
{
class ValidUsernames
{
static void Main(string[] args)
{
string input = Console.ReadLine();
string userName = @"[\w{3,25}]+";
MatchCollection matches = Regex.Matches(input, userName);
List<string> valid = new List<string>();
foreach (var match in matches)
{
if (char.IsLetter(match.ToString().First()))
{
valid.Add(match.ToString());
}
}
int biggestSum = 0;
int pos = 0;
for (int i = 0; i < valid.Count-1; i++)
{
int currSum = valid[i].Length + valid[i + 1].Length;
if (currSum>biggestSum)
{
biggestSum = currSum;
pos = i;
}
}
Console.WriteLine(valid[pos]);
Console.WriteLine(valid[pos+1]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment