Advertisement
alidzhikov

PlusRemove

May 8th, 2015
705
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.14 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. class PlusRemove
  5. {
  6.     static void Main()
  7.     {
  8.         List<List<char>> board = new List<List<char>>();
  9.  
  10.         string lineContents = Console.ReadLine();
  11.         for (int row = 0; lineContents != "END"; row++)
  12.         {
  13.             board.Add(new List<char>(lineContents.Length));
  14.             for (int col = 0; col < lineContents.Length; col++)
  15.             {
  16.                 board[row].Add(lineContents[col]);
  17.             }
  18.             lineContents = Console.ReadLine();
  19.         }
  20.  
  21.         char currentValue = '\0';
  22.         HashSet<KeyValuePair<int, int>> coordinatesSet = new HashSet<KeyValuePair<int, int>>();
  23.         for (int row = 1; row < board.Count - 1; row++)
  24.         {
  25.             for (int col = 1; col < board[row].Count - 1; col++)
  26.             {
  27.                 currentValue = Char.ToLower(board[row][col]);
  28.                 if (col < board[row - 1].Count && currentValue.Equals(Char.ToLower(board[row - 1][col]))
  29.                     && currentValue.Equals(Char.ToLower(board[row][col - 1])) && currentValue.Equals(Char.ToLower(board[row][col + 1]))
  30.                     && col < board[row + 1].Count && currentValue.Equals(Char.ToLower(board[row + 1][col])))
  31.                 {
  32.                     coordinatesSet.Add(new KeyValuePair<int, int>(row, col));
  33.                     coordinatesSet.Add(new KeyValuePair<int, int>(row - 1, col));
  34.                     coordinatesSet.Add(new KeyValuePair<int, int>(row + 1, col));
  35.                     coordinatesSet.Add(new KeyValuePair<int, int>(row, col + 1));
  36.                     coordinatesSet.Add(new KeyValuePair<int, int>(row, col - 1));
  37.                 }
  38.             }
  39.         }
  40.  
  41.         for (int row = 0; row < board.Count; row++)
  42.         {
  43.             for (int col = 0; col < board[row].Count; col++)
  44.             {
  45.                 KeyValuePair<int, int> curKeyValuePair = new KeyValuePair<int, int>(row, col);
  46.                 if (!coordinatesSet.Contains(curKeyValuePair))
  47.                 {
  48.                     Console.Write(board[row][col]);
  49.                 }
  50.             }
  51.             Console.WriteLine();
  52.         }
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement