Skip to content

Instantly share code, notes, and snippets.

@EBojilova
Last active August 29, 2015 14:20
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 EBojilova/bd25811ea47826f5ce4a to your computer and use it in GitHub Desktop.
Save EBojilova/bd25811ea47826f5ce4a to your computer and use it in GitHub Desktop.
10.Plus-Remove
using System;
using System.Collections.Generic;
using System.Text;
class PlusRemove
{
static void Main(string[] args)
{
//Judge mi dava 88/100 tochki
UTF8Encoding utf8 = new UTF8Encoding();
var matrix = new List<char[]>();
var finalMatrix = new List<char[]>();
string input;
int row = 0;
while (!((input = Console.ReadLine()) == "END"))
{
matrix.Add(new char[input.Length]);
matrix[row] = input.ToLower().ToCharArray();
finalMatrix.Add(new char[input.Length]);
finalMatrix[row] = input.ToCharArray();
row++;
}
for (row = 0; row < matrix.Count; row++)
{
for (int col = 0; col < matrix[row].Length; col++)
{
PlusCheck(matrix,finalMatrix, row, col);
}
}
foreach (var symbolsList in finalMatrix)
{
foreach (var symbol in symbolsList)
{
if (symbol != '\0')
{
Console.Write(symbol);
}
}
Console.WriteLine();
}
}
private static void PlusCheck(List<char[]> matrix, List<char[]> finalMatrix, int row, int col)
{
char symbol = matrix[row][col];
if ((row - 1 >= 0 && matrix[row - 1].Length > col && matrix[row - 1][col] == symbol) &&
(row + 1 < matrix.Count && matrix[row + 1].Length > col && matrix[row + 1][col] == symbol) &&
(col - 1 >= 0 && matrix[row][col - 1] == symbol) &&
(col + 1 < matrix[row].Length && matrix[row][col + 1] == symbol))
{
finalMatrix[row][col] = '\0';
finalMatrix[row - 1][col] = '\0';
finalMatrix[row + 1][col] = '\0';
finalMatrix[row][col - 1] = '\0';
finalMatrix[row][col + 1] = '\0';
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment