simonradev

Regeh

Jun 27th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.18 KB | None | 0 0
  1. namespace ConsoleApp1
  2. {
  3.     using System;
  4.     using System.Text;
  5.     using System.Text.RegularExpressions;
  6.    
  7.     public class StartUp
  8.     {
  9.         public static void Main()
  10.         {
  11.             Regex regeh = new Regex(@"\[[^\[\s]+?<(\d+)REGEH(\d+)>[^\[\]\s]+?\]");
  12.  
  13.             StringBuilder result = new StringBuilder();
  14.  
  15.             string inputLine = Console.ReadLine();
  16.  
  17.             int totalIndex = 0;
  18.             foreach (Match match in regeh.Matches(inputLine))
  19.             {
  20.                 totalIndex += int.Parse(match.Groups[1].Value);
  21.                 result.Append(GetElementAtIndex(totalIndex, inputLine));
  22.  
  23.                 totalIndex += int.Parse(match.Groups[2].Value);
  24.                 result.Append(GetElementAtIndex(totalIndex, inputLine));
  25.  
  26.             }
  27.  
  28.             Console.WriteLine(result);
  29.         }
  30.  
  31.         private static char GetElementAtIndex(int index, string inputLine)
  32.         {
  33.             if (index >= 0 && index < inputLine.Length)
  34.             {
  35.                 return inputLine[index];
  36.             }
  37.             else
  38.             {
  39.                 return inputLine[index % (inputLine.Length - 1)];
  40.             }
  41.         }
  42.     }
  43. }
Add Comment
Please, Sign In to add comment