Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Text.RegularExpressions;
- namespace Regeh
- {
- public class StartUp
- {
- public static void Main()
- {
- string input = Console.ReadLine();
- string result = string.Empty;
- int a = input.Length;
- string pattern = @"\[[a-zA-Z]+\<([0-9]+)REGEH([0-9]+)\>[A-Za-z]+\]";
- Regex regex = new Regex(pattern);
- MatchCollection matches = Regex.Matches(input, pattern);
- int nextIndex = 0;
- foreach (Match match in matches)
- {
- int firstIndex = int.Parse(match.Groups[1].ToString()) + nextIndex;
- int secondIndex = firstIndex + int.Parse(match.Groups[2].ToString());
- if (firstIndex > input.Length - 1)
- {
- firstIndex = firstIndex % (input.Length - 1);
- }
- string firstLetter = input.Substring(firstIndex, 1);
- result += firstLetter;
- if (secondIndex > input.Length - 1)
- {
- secondIndex = secondIndex % (input.Length - 1);
- }
- string secondLetter = input.Substring(secondIndex, 1);
- result += secondLetter;
- nextIndex = secondIndex;
- }
- Console.WriteLine(result);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment