Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace _2X2_Squares_in_Matrix
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] matrixSizes = Console.ReadLine()
- .Split(" ", StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToArray();
- int rows = matrixSizes[0];
- int cols = matrixSizes[1];
- char[,] matrix = ReadMatrix(rows, cols);
- int counter = 0;
- for (int rowIndex = 0; rowIndex < rows - 1; rowIndex++)
- {
- for (int colIndex = 0; colIndex < cols - 1; colIndex++)
- {
- if (matrix[rowIndex, colIndex] == matrix[rowIndex, colIndex + 1] &&
- matrix[rowIndex, colIndex] == matrix[rowIndex + 1, colIndex] &&
- matrix[rowIndex, colIndex] == matrix[rowIndex + 1, colIndex + 1])
- {
- counter++;
- }
- }
- }
- Console.WriteLine(counter);
- }
- static char[,] ReadMatrix(int rows, int cols)
- {
- char[,] matrix = new char[rows, cols];
- for (int rowIndex = 0; rowIndex < rows; rowIndex++)
- {
- char[] inputChars = Console.ReadLine()
- .Split(' ', StringSplitOptions.RemoveEmptyEntries)
- .Select(char.Parse)
- .ToArray();
- for (int colIndex = 0; colIndex < cols; colIndex++)
- {
- matrix[rowIndex, colIndex] = inputChars[colIndex];
- }
- }
- return matrix;
- }
- }
- }
Add Comment
Please, Sign In to add comment