Advertisement
Guest User

Untitled

a guest
Aug 8th, 2017
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.27 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Text.RegularExpressions;
  6. using System.Threading.Tasks;
  7.  
  8. namespace _09.BoomingCanon
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             string[] intTokens = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  15.             string input = Console.ReadLine();
  16.             var destroyedTargets = new List<string>();
  17.             int distanceShoot = int.Parse(intTokens[0]);
  18.             int elementsToDestroy = int.Parse(intTokens[1]);
  19.             Regex pattern = new Regex(@"(?<=\\[<]{3})\w+");
  20.  
  21.             string[] text = pattern.Matches(input).Cast<Match>().Select(m => m.Value).ToArray();
  22.             foreach (var line in text)
  23.             {
  24.                 if (elementsToDestroy > line.Length - 1 - elementsToDestroy)
  25.                 {
  26.                     destroyedTargets.Add(line.Substring(distanceShoot));
  27.                 }
  28.                 else
  29.                 {
  30.                     destroyedTargets.Add(line.Substring(distanceShoot, elementsToDestroy));
  31.                 }
  32.                
  33.             }
  34.  
  35.             Console.WriteLine(string.Join("/\\", destroyedTargets));
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement