Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace Squares_in_Matrix
- {
- class Program
- {
- static void Main()
- {
- var nxm = Console.ReadLine()
- .Split()
- .Select(int.Parse)
- .ToArray();
- var rows = nxm[0];
- var cols = nxm[1];
- var count = 0;
- if (rows >= 2 && cols >= 2)
- {
- var matrix = new char[rows, cols];
- for (int row = 0; row < rows; row++)
- {
- var input = Console.ReadLine()
- .Split(' ',StringSplitOptions.RemoveEmptyEntries)
- .Select(char.Parse)
- .ToArray();
- for (int col = 0; col < cols; col++)
- {
- matrix[row, col] = input[col];
- }
- }
- for (int row = 0; row < rows - 1; row++)
- {
- for (int col = 0; col < cols - 1; col++)
- {
- if (matrix[row, col] == matrix[row, col + 1] &&
- matrix[row, col] == matrix[row + 1, col + 1] &&
- matrix[row, col] == matrix[row + 1, col])
- {
- count++;
- }
- }
- }
- }
- Console.WriteLine(count);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment