Advertisement
knoteva

Untitled

Jul 19th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.25 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. namespace _03._Post_Office
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string[] input = Console.ReadLine().Split("|");
  11.  
  12.             string firstPart = input[0];
  13.             string secondPart = input[1];
  14.             string thirdPart = input[2];
  15.             var firstPartReg = @"([#$%*&])(?<capitals>[A-Z]+)(\1)";
  16.             Match firstMatch = Regex.Match(firstPart, firstPartReg);
  17.             string capitals = firstMatch.Groups["capitals"].Value;
  18.  
  19.             for (int index = 0; index < capitals.Length; index++)
  20.             {
  21.                 char firstLetter = capitals[index];
  22.                 int ASCIIcode = firstLetter;
  23.  
  24.                 string secondPattern = $@"{ASCIIcode}:(?<length>[0-9][0-9])";
  25.                 Match secondMatch = Regex.Match(secondPart, secondPattern);
  26.                 int length = int.Parse(secondMatch.Groups["length"].Value);
  27.  
  28.                 string thirdPattern = $@"(?<=\s|^){firstLetter}[^\s]{{{length}}}(?=\s|$)";
  29.                 Match thirdMatch = Regex.Match(thirdPart, thirdPattern);
  30.                 string word = thirdMatch.ToString();
  31.  
  32.                 Console.WriteLine(word);
  33.             }
  34.  
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement