Advertisement
valkata

BoomingCannon - RegEX

Aug 12th, 2017
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.61 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _03_boomingCount
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int[] numbers = Console.ReadLine().Split().Select(int.Parse).ToArray();
  14.             int n = numbers[0];
  15.             int m = numbers[1];
  16.  
  17.             string input = Console.ReadLine();
  18.             int remove = input.IndexOf("\\<<<");
  19.             if(remove == -1)
  20.             {
  21.  
  22.             }
  23.             else
  24.             {
  25.                 string[] field = input
  26.                 .Substring(remove)
  27.                 .Split(new string[] { "\\<<<" }, StringSplitOptions.RemoveEmptyEntries)
  28.                 .ToArray();
  29.                 List<string> destroyed = new List<string>();
  30.  
  31.                 foreach (var canon in field)
  32.                 {
  33.                     if (n <= canon.Length - 1)
  34.                     {
  35.                         int length = n + m;
  36.                         if (length > canon.Length)
  37.                         {
  38.                             string currDestroyed = canon.Substring(n, canon.Length - n);
  39.                             destroyed.Add(currDestroyed);
  40.                         }
  41.                         else
  42.                         {
  43.                             string currDestroyed = canon.Substring(n, m);
  44.                             destroyed.Add(currDestroyed);
  45.                         }
  46.                     }
  47.                 }
  48.  
  49.                 Console.WriteLine(string.Join("/\\", destroyed));
  50.             }
  51.            
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement