Advertisement
Danny_Berova

01.Regeh

Feb 3rd, 2018
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.43 KB | None | 0 0
  1. namespace _01.Regeh
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.     using System.Text;
  6.     using System.Text.RegularExpressions;
  7.  
  8.     public class Regeh
  9.     {
  10.         public static void Main()
  11.         {
  12.             var pattern = @"\[[^\s\[]+<([0-9]+)REGEH([0-9]+)>[^\s\]]+\]";
  13.             var regex = new Regex(pattern);
  14.             var output = new StringBuilder();
  15.             var indices = new List<int>();
  16.  
  17.             var inputLine = Console.ReadLine();
  18.  
  19.             if (regex.IsMatch(inputLine))
  20.             {
  21.                 var matches = regex.Matches(inputLine);
  22.                 var inputArray = inputLine.ToCharArray();
  23.  
  24.                 for (int i = 0; i < matches.Count; i++)
  25.                 {
  26.                     var currentMatch = matches[i];
  27.                     indices.Add(int.Parse(currentMatch.Groups[1].Value));
  28.                     indices.Add(int.Parse(currentMatch.Groups[2].Value));
  29.  
  30.                 }
  31.  
  32.                 var currentIndex = 0;
  33.                 for (int i = 0; i < indices.Count; i++)
  34.                 {
  35.                     currentIndex += indices[i];
  36.                     if (currentIndex > inputLine.Length - 1)
  37.                     {
  38.                         currentIndex %= inputLine.Length - 1;
  39.                     }
  40.  
  41.                     output.Append(inputLine[currentIndex]);
  42. ;                }
  43.             }
  44.  
  45.             Console.WriteLine(output);
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement