svetlozar_kirkov

Plus Remove [Advanced C# Practice]

Oct 7th, 2015
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.39 KB | None | 0 0
  1. namespace Plus_Remove
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.     using System.Linq;
  6.  
  7.     internal sealed class App
  8.     {
  9.         internal static void Main()
  10.         {
  11.             List<string> inputLines = new List<string>();
  12.  
  13.             string currentInputLine = Console.ReadLine();
  14.  
  15.             while (!currentInputLine.Equals("END"))
  16.             {
  17.                 inputLines.Add(currentInputLine);
  18.                 currentInputLine = Console.ReadLine();
  19.             }
  20.  
  21.             List<char[]> result = inputLines.Select(line => line.ToCharArray()).ToList();
  22.  
  23.             if (inputLines.Count <= 2)
  24.             {
  25.                 foreach (var line in inputLines)
  26.                 {
  27.                     Console.WriteLine(line);
  28.                 }
  29.  
  30.                 return;
  31.             }
  32.  
  33.             for (int i = 0; i < inputLines.Count - 2; i++)
  34.             {
  35.                 for (int j = 0; j < inputLines[i].Length;)
  36.                 {
  37.                     try
  38.                     {
  39.                         char top = char.ToLower(inputLines[i][j]);
  40.                         char left = char.ToLower(inputLines[i + 1][j - 1]);
  41.                         char right = char.ToLower(inputLines[i + 1][j + 1]);
  42.                         char middle = char.ToLower(inputLines[i + 1][j]);
  43.                         char bottom = char.ToLower(inputLines[i + 2][j]);
  44.                        
  45.                         if (top == left && left == right && right == middle && middle == bottom)
  46.                         {
  47.                             result[i][j] = ' ';
  48.                             result[i + 1][j] = ' ';
  49.                             result[i + 2][j] = ' ';
  50.                             result[i + 1][j + 1] = ' ';
  51.                             result[i + 1][j - 1] = ' ';
  52.                         }
  53.  
  54.                         j++;
  55.                     }
  56.                     catch (IndexOutOfRangeException)
  57.                     {
  58.                         j++;
  59.                     }
  60.                 }
  61.             }
  62.  
  63.             foreach (var line in result)
  64.             {
  65.                 foreach (var character in line)
  66.                 {
  67.                     if (!character.Equals(' '))
  68.                     {
  69.                         Console.Write(character);
  70.                     }
  71.                 }
  72.  
  73.                 Console.WriteLine();
  74.             }
  75.         }
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment