Advertisement
kalitarix

Post Office

Nov 23rd, 2018
1,472
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 PostOffice
  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.  
  16.             string firstPattern = @"([#$%*&])(?<capitals>[A-Z]+)(\1)";
  17.             Match firstMatch = Regex.Match(firstPart, firstPattern);
  18.             string capitals = firstMatch.Groups["capitals"].Value;
  19.  
  20.             for (int index = 0; index < capitals.Length; index++)
  21.             {
  22.                 char startLetter = capitals[index];
  23.                 int ASCIIcode = startLetter;
  24.  
  25.                 string secondPattern = $@"{ASCIIcode}:(?<length>[0-9][0-9])";
  26.                 Match secondMatch = Regex.Match(secondPart, secondPattern);
  27.                 int length = int.Parse(secondMatch.Groups["length"].Value);
  28.  
  29.                 string thirdPattern = $@"(?<=\s|^){startLetter}[^\s]{{{length}}}(?=\s|$)";
  30.                 Match thirdMatch = Regex.Match(thirdPart, thirdPattern);
  31.                 string word = thirdMatch.ToString();
  32.  
  33.                 Console.WriteLine(word);
  34.             }
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement