Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text.RegularExpressions;
- using System.Linq;
- namespace _3._Post_Office
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] symbols = Console.ReadLine().Split('|').ToArray();
- string firstPattern = @"([#$%*&])[A-Z]+\1";
- string secondPattern = @"[0-9]{2}:[0-9]{2}";
- string letterPattern = @"[A-Z]";
- Match matchLetters = Regex.Match(symbols[0], firstPattern);
- MatchCollection matchesLetter = Regex.Matches(matchLetters.ToString(), letterPattern);
- MatchCollection matchesNumbers = Regex.Matches(symbols[1], secondPattern);
- var number = new Dictionary<int, int>();
- var letters = new Dictionary<string, int>();
- foreach (Match item in matchesNumbers)
- {
- int[] arr = item.ToString().Split(':').Select(x => x.TrimStart('0')).Select(int.Parse).ToArray();
- if(number.ContainsKey(arr[0]))
- {
- continue;
- }
- number.Add(arr[0], arr[1]);
- }
- foreach (Match item in matchesLetter)
- {
- foreach (var items in number)
- {
- if((int)Convert.ToChar(item.ToString()) == items.Key)
- {
- if(letters.ContainsKey(item.ToString()))
- {
- continue;
- }
- letters.Add(item.ToString(), items.Value+1);
- }
- }
- }
- string[] words = symbols[2].Split(' ').ToArray();
- foreach (var item in letters)
- {
- foreach (var items in words)
- {
- if(items[0] == Convert.ToChar(item.Key) && items.Length == item.Value)
- {
- Console.WriteLine(items);
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement