Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text.RegularExpressions;
- namespace _05KeyReplacer
- {
- class Program
- {
- static void Main(string[] args)
- {
- string key = Console.ReadLine();
- string text = Console.ReadLine();
- string start = string.Empty;
- for (int i = 0; i < key.Length; i++)
- {
- char curr = key[i];
- if (curr == '|' || curr == '\\' || curr == '<')
- {
- break;
- }
- else if (char.IsLetter(curr))
- {
- start += curr;
- }
- }
- string reversedEnd = string.Empty;
- for (int i = key.Length - 1; i >= 0; i--)
- {
- char curr = key[i];
- if (curr == '|' || curr == '\\' || curr == '<')
- {
- break;
- }
- else if (char.IsLetter(curr))
- {
- reversedEnd += curr;
- }
- }
- string end = string.Empty;
- for (int i = reversedEnd.Length - 1; i >= 0; i--)
- {
- char curr = reversedEnd[i];
- end += curr;
- }
- string pattern = $@"({start}(?<word>.{{0,}}?){end})";
- string result = string.Empty;
- MatchCollection matches = Regex.Matches(text, pattern);
- foreach (Match match in matches)
- {
- string word = match.Groups["word"].Value;
- result += word;
- }
- if (result==string.Empty)
- {
- Console.WriteLine("Empty result");
- return;
- }
- Console.WriteLine(result);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment