Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Filkolev
Created May 27, 2015 21:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Filkolev/1ae9e624ff517ab77882 to your computer and use it in GitHub Desktop.
Save Filkolev/1ae9e624ff517ab77882 to your computer and use it in GitHub Desktop.
X Removal
using System;
using System.Collections.Generic;
public class XRemoval
{
public static void Main()
{
List<string> matrix = new List<string>();
List<bool[]> symbolsToRemove = new List<bool[]>();
string input = Console.ReadLine();
while (input != "END")
{
matrix.Add(input);
symbolsToRemove.Add(new bool[input.Length]);
input = Console.ReadLine();
}
for (int row = 0; row < matrix.Count - 2; row++)
{
for (int column = 2; column < matrix[row].Length; column++)
{
if (matrix[row + 1].Length < column
|| matrix[row + 2].Length < column + 1)
{
continue;
}
char currentSymbol = char.ToLower(matrix[row][column]);
if (char.ToLower(matrix[row][column - 2]) == currentSymbol
&& char.ToLower(matrix[row + 1][column - 1]) == currentSymbol
&& char.ToLower(matrix[row + 2][column - 2]) == currentSymbol
&& char.ToLower(matrix[row + 2][column]) == currentSymbol)
{
symbolsToRemove[row][column - 2] = true;
symbolsToRemove[row][column] = true;
symbolsToRemove[row + 1][column - 1] = true;
symbolsToRemove[row + 2][column - 2] = true;
symbolsToRemove[row + 2][column] = true;
}
}
}
for (int row = 0; row < matrix.Count; row++)
{
for (int column = 0; column < matrix[row].Length; column++)
{
if (symbolsToRemove[row][column])
{
continue;
}
Console.Write(matrix[row][column]);
}
Console.WriteLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment