Advertisement
Guest User

Untitled

a guest
Jun 12th, 2017
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.29 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.     public class ValidUsernames
  11.     {
  12.         public static void Main()
  13.         {
  14.             var users = new List<string>();
  15.             string[] input = Console.ReadLine().Split(new char[] { ' ', '/', '\\', '(', ')' }, StringSplitOptions.RemoveEmptyEntries);
  16.  
  17.             string pattern = @"^[A-Za-z]\w{2,24}$";
  18.             Regex regex = new Regex(pattern);
  19.  
  20.             foreach (var user in input)
  21.             {
  22.                 if (regex.IsMatch(user))
  23.                 {
  24.                     users.Add(user);
  25.                 }
  26.             }
  27.  
  28.             int sumlength = 0;
  29.             int maxSumLength = 0;
  30.             int firstUserIndex = 0;
  31.  
  32.             for (int i = 0; i < users.Count - 1; i++)
  33.             {
  34.                 sumlength = users[i].Length + users[i + 1].Length;
  35.                 if (sumlength > maxSumLength)
  36.                 {
  37.                     maxSumLength = sumlength;
  38.                     firstUserIndex = i;
  39.                 }
  40.             }
  41.  
  42.             Console.WriteLine(users[firstUserIndex]);
  43.             Console.WriteLine(users[firstUserIndex+1]);
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement