MiroslavKisov

Regeh

Feb 5th, 2018
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.37 KB | None | 0 0
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. namespace Regeh
  5. {
  6.     public class StartUp
  7.     {
  8.         public static void Main()
  9.         {
  10.             string input = Console.ReadLine();
  11.             string result = string.Empty;
  12.             int a = input.Length;
  13.             string pattern = @"\[[a-zA-Z]+\<([0-9]+)REGEH([0-9]+)\>[A-Za-z]+\]";
  14.             Regex regex = new Regex(pattern);
  15.             MatchCollection matches = Regex.Matches(input, pattern);
  16.             int nextIndex = 0;
  17.             foreach (Match match in matches)
  18.             {
  19.                 int firstIndex = int.Parse(match.Groups[1].ToString()) + nextIndex;
  20.                 int secondIndex = firstIndex + int.Parse(match.Groups[2].ToString());
  21.                 if (firstIndex > input.Length - 1)
  22.                 {
  23.                     firstIndex = firstIndex % (input.Length - 1);
  24.                 }
  25.                 string firstLetter = input.Substring(firstIndex, 1);
  26.                 result += firstLetter;
  27.                 if (secondIndex > input.Length - 1)
  28.                 {
  29.                     secondIndex = secondIndex % (input.Length - 1);
  30.                 }
  31.                 string secondLetter = input.Substring(secondIndex, 1);
  32.                 result += secondLetter;
  33.                 nextIndex = secondIndex;
  34.             }
  35.             Console.WriteLine(result);
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment