Advertisement
miroLLL

AnonumousVox

Feb 25th, 2018
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.03 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace _03Problem_AnonumousVox
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             string placeholderBlocks = Console.ReadLine();
  13.             string[] values = Console.ReadLine().Split(new char[]{'{', '}'},StringSplitOptions.RemoveEmptyEntries).ToArray();
  14.  
  15.             string pattern = @"(?<startEnd>[A-Z-a-z]+)(?<placeholder>.+)(\k<startEnd>)";
  16.             MatchCollection matchedPlaceholders = Regex.Matches(placeholderBlocks, pattern);
  17.  
  18.             int index = 0;
  19.  
  20.             foreach (Match matched in matchedPlaceholders)
  21.             {
  22.                 string oldPlaceholder = matched.Groups["placeholder"].Value;
  23.                 string newPlaceholder = values[index];
  24.  
  25.                 placeholderBlocks = placeholderBlocks.Replace(oldPlaceholder, newPlaceholder);
  26.                 index++;
  27.             }
  28.  
  29.             Console.WriteLine(placeholderBlocks);
  30.         }
  31.     }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement