Advertisement
YavorGrancharov

03. Anonymous Vox(90%)

Nov 8th, 2017
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.97 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. namespace exam03
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string statement = Console.ReadLine();
  11.  
  12.             string placeholder = Console.ReadLine();
  13.  
  14.             string pattern = @"([a-zA-Z]+)(.+)(\1)";
  15.  
  16.             string recognition = @"\{(.*?[a-zA-Z]+.*?)\}";
  17.  
  18.             string replacer = string.Empty;
  19.             string toReplace = string.Empty;
  20.  
  21.             MatchCollection m = Regex.Matches(statement, pattern);
  22.             MatchCollection n = Regex.Matches(placeholder, recognition);
  23.  
  24.             int len = Math.Min(m.Count, n.Count);
  25.             for (int i = 0; i < len; i++)
  26.             {
  27.                 toReplace = m[i].Groups[2].Value.ToString();
  28.                 replacer = n[i].Groups[1].Value.ToString();
  29.                 statement = statement.Replace(toReplace, replacer);
  30.             }
  31.             Console.WriteLine(statement);
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement