Advertisement
dimipan80

Plus-Remove

May 10th, 2015
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.28 KB | None | 0 0
  1. namespace Plus_Remove
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.  
  6.     class PlusRemove
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             List<string> textLines = new List<string>();
  11.             List<bool[]> output = new List<bool[]>();
  12.             string inputLine = Console.ReadLine();
  13.             while (inputLine != "END")
  14.             {
  15.                 textLines.Add(inputLine);
  16.                 output.Add(new bool[inputLine.Length]);
  17.  
  18.                 inputLine = Console.ReadLine();
  19.             }
  20.  
  21.             for (int row = 0; row < textLines.Count; row++)
  22.             {
  23.                 for (int col = 1; col < textLines[row].Length; col++)
  24.                 {
  25.                     if (!CheckIsInsideTheMatrix(textLines, row, col)) continue;
  26.  
  27.                     RemovePlusShape(textLines, row, col, output);
  28.                 }
  29.             }
  30.  
  31.             PrintResults(textLines, output);
  32.         }
  33.  
  34.         private static bool CheckIsInsideTheMatrix(List<string> matrix, int row, int col)
  35.         {
  36.             return row + 2 < matrix.Count && col + 1 < matrix[row + 1].Length &&
  37.                 col < matrix[row + 2].Length;
  38.         }
  39.  
  40.         private static void RemovePlusShape(List<string> matrix, int row, int col, List<bool[]> result)
  41.         {
  42.             char plus = char.ToLower(matrix[row][col]);
  43.             if (char.ToLower(matrix[row + 1][col - 1]) != plus ||
  44.                 char.ToLower(matrix[row + 1][col]) != plus ||
  45.                 char.ToLower(matrix[row + 1][col + 1]) != plus ||
  46.                 char.ToLower(matrix[row + 2][col]) != plus) return;
  47.  
  48.             result[row][col] = true;
  49.             result[row + 1][col - 1] = true;
  50.             result[row + 1][col] = true;
  51.             result[row + 1][col + 1] = true;
  52.             result[row + 2][col] = true;
  53.         }
  54.  
  55.         private static void PrintResults(List<string> matrix, List<bool[]> output)
  56.         {
  57.             for (int row = 0; row < matrix.Count; row++)
  58.             {
  59.                 for (int col = 0; col < matrix[row].Length; col++)
  60.                 {
  61.                     if (output[row][col]) continue;
  62.  
  63.                     Console.Write(matrix[row][col]);
  64.                 }
  65.  
  66.                 Console.WriteLine();
  67.             }
  68.         }
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement