Advertisement
martinvalchev

Valid_Usernames

Feb 25th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.28 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 Valid_Usernames
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             string[] input = Console.ReadLine().Split(new char[] { '(', ')', ' ', '\\', '/' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  15.             string pattern = @"(^[A-Za-z][\w]{2,24})";
  16.             List<string> result = new List<string>();
  17.  
  18.             foreach (var member in input)
  19.             {
  20.                 if (Regex.IsMatch(member, pattern) && member.Length>=3 && member.Length<=25)
  21.                 {
  22.                     result.Add(member);
  23.                 }
  24.             }
  25.  
  26.             int counter = 0;
  27.             int counterMax = 0;
  28.             int position = 0;
  29.             for (int i = 0; i < result.Count - 1; i++)
  30.             {
  31.                 counter = result[i].Length + result[i + 1].Length;
  32.                 if (counter> counterMax)
  33.                 {
  34.                     counterMax = counter;
  35.                     position = i;
  36.  
  37.                 }
  38.             }
  39.             Console.WriteLine(result[position]);
  40.             Console.WriteLine(result[position + 1]);
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement