Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* You are given a line of usernames, between one of the following symbols: space, “/”, “\”, “(“, “)”. First you have to export all valid usernames. A valid username starts with a letter and can contain only letters, digits and “_”. It cannot be less than 3 or more than 25 symbols long. Your task is to sum the length of every 2 consecutive valid usernames and print on the console the 2 valid usernames with biggest sum of their lengths, each on a separate line.
- * The usernames should start with a letter and can contain only letters, digits and “_”. The username cannot be less than 3 or more than 25 symbols long.
- * Print at the console the 2 consecutive valid usernames with the biggest sum of their lengths each on a separate line. If there are 2 or more couples of usernames with the same sum of their lengths, print he left most. */
- namespace _05.ValidUsernames
- {
- using System;
- using System.Text.RegularExpressions;
- class ValidUsernames
- {
- static void Main(string[] args)
- {
- string text = Console.ReadLine();
- const string pattern = @"\b[A-Za-z]\w{2,24}\b";
- MatchCollection matches = Regex.Matches(text, pattern);
- int start = 0;
- int maxLength = 0;
- for (int i = 0; i + 1 < matches.Count; i++)
- {
- int length = matches[i].Length + matches[i + 1].Length;
- if (length > maxLength)
- {
- maxLength = length;
- start = i;
- }
- }
- for (int j = start; j < start + 2; j++)
- {
- Console.WriteLine(matches[j]);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement