Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Globalization;
- using System.Text.RegularExpressions;
- using System.Collections.Generic;
- namespace lab3.BoomingCannon
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] coordinates = Console.ReadLine().Split(' ');
- int distance = int.Parse(coordinates[0], NumberFormatInfo.InvariantInfo);
- int elementsToDestroy = int.Parse(coordinates[1], NumberFormatInfo.InvariantInfo);
- string inputTarget = Console.ReadLine();
- Regex targetPatern = new Regex(@"\\<<<(?<target>[^\\<<<]+)");
- MatchCollection collection = targetPatern.Matches(inputTarget);
- List<string> result = new List<string>();
- foreach (Match m in collection)
- {
- string target = m.Groups["target"].Value;
- string destroyedTarget = GetDestroyedTarget(distance, elementsToDestroy, target);
- result.Add(destroyedTarget);
- }
- Console.WriteLine(string.Join("/\\",result));
- }
- static string GetDestroyedTarget(int index,int count ,string target)
- {
- string destroyed = "";
- int countLetters = 0;
- for (int i = index; i < target.Length; i++)
- {
- if (countLetters == count)
- {
- return destroyed;
- }
- destroyed += target[i];
- countLetters++;
- }
- return destroyed;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment