WindFell

Post Office

Aug 29th, 2018
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.44 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4.  
  5. class PostOffice
  6. {
  7.     static void Main(string[] args)
  8.     {
  9.         string[] input = Console.ReadLine()
  10.             .Split('|', StringSplitOptions.RemoveEmptyEntries);
  11.         string capitalsPattern = @"(?<symbol>[$#%*&])(?<capitals>[A-Z]+)\k<symbol>";
  12.         string firstLetterAndLengthPattern = @"(?<capital>6[5-9]|[78][0-9]|90):(?<length>\d{2})";
  13.  
  14.         string capitals = Regex.Match(input[0], capitalsPattern).Groups["capitals"].Value;
  15.         MatchCollection capitalsAndLengthMatches = Regex.Matches(input[1], firstLetterAndLengthPattern);
  16.         string[] words = input[2].Split();
  17.         List<string> result = new List<string>();
  18.  
  19.         foreach (string word in words)
  20.         {
  21.             foreach (Match match in capitalsAndLengthMatches)
  22.             {
  23.                 char capital = (char)int.Parse(match.Groups["capital"].Value);
  24.                 int length = int.Parse(match.Groups["length"].Value);
  25.                 if (capitals.Contains(capital))
  26.                 {
  27.                     string wordPattern = $@"^{capital}[^ ]{{{length}}}$";
  28.                     if (Regex.IsMatch(word, wordPattern))
  29.                     {
  30.                         result.Add(word);
  31.                         break;
  32.                     }
  33.                 }
  34.             }
  35.         }
  36.  
  37.         Console.WriteLine(string.Join(Environment.NewLine, result));
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment