Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace ConsoleApp1
- {
- using System;
- using System.Text;
- using System.Text.RegularExpressions;
- public class StartUp
- {
- public static void Main()
- {
- Regex regeh = new Regex(@"\[[^\[\s]+?<(\d+)REGEH(\d+)>[^\[\]\s]+?\]");
- StringBuilder result = new StringBuilder();
- string inputLine = Console.ReadLine();
- int totalIndex = 0;
- foreach (Match match in regeh.Matches(inputLine))
- {
- totalIndex += int.Parse(match.Groups[1].Value);
- result.Append(GetElementAtIndex(totalIndex, inputLine));
- totalIndex += int.Parse(match.Groups[2].Value);
- result.Append(GetElementAtIndex(totalIndex, inputLine));
- }
- Console.WriteLine(result);
- }
- private static char GetElementAtIndex(int index, string inputLine)
- {
- if (index >= 0 && index < inputLine.Length)
- {
- return inputLine[index];
- }
- else
- {
- return inputLine[index % (inputLine.Length - 1)];
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment