Advertisement
CR7CR7

Mines

Nov 23rd, 2022
632
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.53 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace Mines
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             var input = Console.ReadLine();
  13.  List<char> mineLine = input.ToCharArray().ToList();
  14.             var matches = Regex.Matches(input, @"<..>");
  15.            
  16.             foreach (Match mine in matches)
  17.   {
  18.                 int index = mineLine.IndexOf(mine.ToString()[0]);
  19.                
  20.                 int mineStartIndex = index + 1;
  21.                 int mineEndIndex = index + 2;
  22.                 char mineFirstLetter = mineLine[mineStartIndex];
  23.                 char mineSecondLetter = mineLine[mineEndIndex];
  24.                 int minePower = Math.Abs(mineFirstLetter - mineSecondLetter);
  25.  
  26.                 int blastAwayStartIndex = index - minePower;
  27.                 int blastAwayEndIndex = index - 1 + 4 + minePower;
  28.  
  29.                 if (blastAwayStartIndex < 0)
  30.                 {
  31.                     blastAwayStartIndex = 0;
  32.                 }
  33.                
  34.                 if (blastAwayEndIndex >= mineLine.Count)
  35.                 {
  36.                     blastAwayEndIndex = mineLine.Count - 1;
  37.                 }
  38.  
  39.                 for (int i = blastAwayStartIndex; i <= blastAwayEndIndex; i++)
  40.                 {
  41.                     mineLine.RemoveAt(i);
  42.                     mineLine.Insert(i, '_');
  43.                 }
  44.             }
  45.  
  46.             Console.WriteLine(string.Join("", mineLine));
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement