Advertisement
North_Point

03. Booming Cannon

Aug 7th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.40 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 _03.Booming_Cannon
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             int[] numbers = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  15.             string input = Console.ReadLine();
  16.             int distance = numbers[0];
  17.             int countOfChars = numbers[1];
  18.             var result = new List<string>();
  19.             string element = "";
  20.             string regex = @"(?<=\\<<<)[<]*[^\\<<<]+[<]*[^\\<<<]+";
  21.             MatchCollection filteredInput = Regex.Matches(input, regex);
  22.             foreach (var word in filteredInput)
  23.             {
  24.                 element = "";
  25.                 if (distance <= word.ToString().Length)
  26.                 {
  27.                     element = word.ToString().Substring(distance);
  28.                     if (element.Length >= countOfChars)
  29.                     {
  30.                         element = element.Substring(0, countOfChars);
  31.                     }
  32.                 }
  33.                 if (element != string.Empty)
  34.                 {
  35.                     result.Add(element);
  36.                 }
  37.             }
  38.             if (result.Count > 0)
  39.             {
  40.                 Console.WriteLine(string.Join("/\\", result));
  41.             }
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement