MiroslavKisov

2X2SquareInMatrix

Jan 28th, 2018
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.38 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _2X2SquaresInMatrix
  5. {
  6.     public class StartUp
  7.     {
  8.         public static void Main(string[] args)
  9.         {
  10.             var size = Console.ReadLine()
  11.                 .Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries)
  12.                 .Select(int.Parse)
  13.                 .ToArray();
  14.             var matrix = new char[size[0], size[1]];
  15.             var counter = 0;
  16.             for (int i = 0; i < matrix.GetLength(0); i++)
  17.             {
  18.                 var rows = Console.ReadLine()
  19.                     .Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries)
  20.                     .Select(char.Parse)
  21.                     .ToArray();
  22.                 for (int j = 0; j < matrix.GetLength(1); j++)
  23.                 {
  24.                     matrix[i, j] = rows[j];
  25.                 }
  26.             }
  27.             for (int i = 0; i < matrix.GetLength(0) - 1; i++)
  28.             {
  29.                 for (int j = 0; j < matrix.GetLength(1) - 1; j++)
  30.                 {
  31.                     if (matrix[i, j] == matrix[i, j + 1]
  32.                         && matrix[i, j] == matrix[i + 1, j]
  33.                         && matrix[i ,j] == matrix[i + 1,j + 1])
  34.                     {
  35.                         counter++;
  36.                     }
  37.                 }
  38.             }
  39.             Console.WriteLine(counter++);
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment