Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace X_Removal
- {
- using System;
- using System.Collections.Generic;
- class XRemoval
- {
- static void Main(string[] args)
- {
- List<string> textLines = new List<string>();
- List<bool[]> output = new List<bool[]>();
- string inputLine = Console.ReadLine();
- while (inputLine != "END")
- {
- textLines.Add(inputLine);
- output.Add(new bool[inputLine.Length]);
- inputLine = Console.ReadLine();
- }
- for (int row = 0; row < textLines.Count; row++)
- {
- for (int col = 0; col < textLines[row].Length; col++)
- {
- if (col + 2 >= textLines[row].Length ||
- row + 2 >= textLines.Count || col + 1 >= textLines[row + 1].Length ||
- col + 2 >= textLines[row + 2].Length) continue;
- RemoveXShape(textLines, row, col, output);
- }
- }
- PrintResults(textLines, output);
- }
- private static void RemoveXShape(List<string> matrix, int row, int col, List<bool[]> result)
- {
- char xshape = char.ToLower(matrix[row][col]);
- if (char.ToLower(matrix[row][col + 2]) != xshape ||
- char.ToLower(matrix[row + 1][col + 1]) != xshape ||
- char.ToLower(matrix[row + 2][col]) != xshape ||
- char.ToLower(matrix[row + 2][col + 2]) != xshape) return;
- result[row][col] = true;
- result[row][col + 2] = true;
- result[row + 1][col + 1] = true;
- result[row + 2][col] = true;
- result[row + 2][col + 2] = true;
- }
- private static void PrintResults(List<string> matrix, List<bool[]> result)
- {
- for (int row = 0; row < matrix.Count; row++)
- {
- for (int col = 0; col < matrix[row].Length; col++)
- {
- if (result[row][col]) continue;
- Console.Write(matrix[row][col]);
- }
- Console.WriteLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement