Advertisement
dimipan80

X-Removal

May 29th, 2015
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.19 KB | None | 0 0
  1. namespace X_Removal
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.  
  6.     class XRemoval
  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 = 0; col < textLines[row].Length; col++)
  24.                 {
  25.                     if (col + 2 >= textLines[row].Length ||
  26.                         row + 2 >= textLines.Count || col + 1 >= textLines[row + 1].Length ||
  27.                         col + 2 >= textLines[row + 2].Length) continue;
  28.  
  29.                     RemoveXShape(textLines, row, col, output);
  30.                 }
  31.             }
  32.  
  33.             PrintResults(textLines, output);
  34.         }
  35.  
  36.         private static void RemoveXShape(List<string> matrix, int row, int col, List<bool[]> result)
  37.         {
  38.             char xshape = char.ToLower(matrix[row][col]);
  39.             if (char.ToLower(matrix[row][col + 2]) != xshape ||
  40.                 char.ToLower(matrix[row + 1][col + 1]) != xshape ||
  41.                 char.ToLower(matrix[row + 2][col]) != xshape ||
  42.                 char.ToLower(matrix[row + 2][col + 2]) != xshape) return;
  43.  
  44.             result[row][col] = true;
  45.             result[row][col + 2] = true;
  46.             result[row + 1][col + 1] = true;
  47.             result[row + 2][col] = true;
  48.             result[row + 2][col + 2] = true;
  49.         }
  50.  
  51.         private static void PrintResults(List<string> matrix, List<bool[]> result)
  52.         {
  53.             for (int row = 0; row < matrix.Count; row++)
  54.             {
  55.                 for (int col = 0; col < matrix[row].Length; col++)
  56.                 {
  57.                     if (result[row][col]) continue;
  58.  
  59.                     Console.Write(matrix[row][col]);
  60.                 }
  61.  
  62.                 Console.WriteLine();
  63.             }
  64.         }
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement