Advertisement
Guest User

3.Post Office

a guest
Jul 31st, 2020
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.10 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4. using System.Linq;
  5.  
  6. namespace _3._Post_Office
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             string[] symbols = Console.ReadLine().Split('|').ToArray();
  13.  
  14.             string firstPattern = @"([#$%*&])[A-Z]+\1";
  15.             string secondPattern = @"[0-9]{2}:[0-9]{2}";
  16.             string letterPattern = @"[A-Z]";
  17.  
  18.             Match matchLetters = Regex.Match(symbols[0], firstPattern);
  19.             MatchCollection matchesLetter = Regex.Matches(matchLetters.ToString(), letterPattern);
  20.  
  21.             MatchCollection matchesNumbers = Regex.Matches(symbols[1], secondPattern);
  22.  
  23.             var number = new Dictionary<int, int>();
  24.             var letters = new Dictionary<string, int>();
  25.  
  26.             foreach (Match item in matchesNumbers)
  27.             {
  28.                 int[] arr = item.ToString().Split(':').Select(x => x.TrimStart('0')).Select(int.Parse).ToArray();
  29.  
  30.                 if(number.ContainsKey(arr[0]))
  31.                 {
  32.                     continue;
  33.                 }
  34.                 number.Add(arr[0], arr[1]);
  35.             }
  36.  
  37.             foreach (Match item in matchesLetter)
  38.             {
  39.                 foreach (var items in number)
  40.                 {
  41.                     if((int)Convert.ToChar(item.ToString()) == items.Key)
  42.                     {
  43.                         if(letters.ContainsKey(item.ToString()))
  44.                         {
  45.                             continue;
  46.                         }
  47.                         letters.Add(item.ToString(), items.Value+1);
  48.                     }
  49.                 }
  50.  
  51.             }
  52.             string[] words = symbols[2].Split(' ').ToArray();
  53.  
  54.             foreach (var item in letters)
  55.             {
  56.                 foreach (var items in words)
  57.                 {
  58.                     if(items[0] == Convert.ToChar(item.Key) && items.Length == item.Value)
  59.                     {
  60.                         Console.WriteLine(items);
  61.                     }
  62.                 }
  63.             }
  64.         }
  65.     }
  66. }
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement