Advertisement
social1986

Untitled

Jan 31st, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.01 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. namespace _01.Regeh
  5. {
  6.     public class Startup
  7.     {
  8.         public static void Main()
  9.         {
  10.             var input = Console.ReadLine();
  11.             var pattern = new Regex(@"\[\w+<(\d+)REGEH(\d+)>\w+]");
  12.  
  13.             var matches = pattern.Matches(input);
  14.             var index = 0;
  15.             var result = string.Empty;
  16.             foreach (Match match in matches)
  17.             {
  18.                 index += int.Parse(match.Groups[1].ToString());
  19.  
  20.                 if (index > input.Length - 1)
  21.                 {
  22.                     index = (index % input.Length) + 1;
  23.                 }
  24.                 result += input[index];
  25.                 index += int.Parse(match.Groups[2].ToString());
  26.                 if (index > input.Length - 1)
  27.                 {
  28.                     index = (index % input.Length) + 1;
  29.  
  30.                 }
  31.                 result += input[index];
  32.             }
  33.             Console.WriteLine(result);
  34.         }
  35.     }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement