Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Text.RegularExpressions;
- namespace Problem03PostOffice
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] input = Console.ReadLine().Split('|');
- var symbolAndTimes = new Dictionary<char, int>();
- string firstPartPattern = @"([#$%*&])[A-Z]+\1";
- string secondPartPattern = @"(?<asciiCode>\d{2}):(?<length>\d{2})";
- string firstPart = input[0];
- string secondPart = input[1];
- string thirdPart = input[2];
- MatchCollection partOne = Regex.Matches(firstPart, firstPartPattern);
- string capitalLetters = string.Empty;
- foreach (Match item in partOne)
- {
- capitalLetters += item.Value.Remove(0, 1).Remove(item.Value.Length - 2, 1);
- }
- MatchCollection partTwo = Regex.Matches(secondPart, secondPartPattern);
- foreach (Match item in partTwo)
- {
- string[] asciiCodeAndLength = item.Value.Split(':');
- int asciiCode = int.Parse(asciiCodeAndLength[0]);
- int length = int.Parse(asciiCodeAndLength[1]) + 1;
- //Console.WriteLine("ASCII: " + asciiCode);
- //Console.WriteLine("Length: " + length);
- if (!symbolAndTimes.ContainsKey((char)asciiCode))
- {
- symbolAndTimes.Add((char)asciiCode, length);
- }
- }
- var dictionary = new Dictionary<char, int>();
- for (int i = 0; i < capitalLetters.Length; i++)
- {
- foreach (char key in symbolAndTimes.Keys)
- {
- if (key == capitalLetters[i])
- {
- dictionary.Add(key, symbolAndTimes[key]);
- }
- }
- }
- string[] words = thirdPart.Split(' ');
- for (int i = 0; i < words.Length; i++)
- {
- if (dictionary.ContainsKey(words[i][0]))
- {
- if (words[i].Length == dictionary[words[i][0]])
- {
- Console.WriteLine(words[i]);
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement