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(string[] args)
- {
- int [] dimensions = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
- int rows = dimensions[0];
- int cols = dimensions[1];
- char[,] matrix = new char[rows, cols];
- for (int row = 0; row < rows; row++)
- {
- char[] currentRow = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries).Select(char.Parse).ToArray();
- for (int col = 0; col < cols; col++)
- {
- matrix[row,col] = currentRow[col];
- }
- }
- int count = 0;
- for (int row = 0; row < rows-1; row++)
- {
- for (int col = 0; col < cols-1; col ++)
- {
- char currentChar = matrix[row,col];
- if (currentChar == matrix[row, col + 1] &&
- currentChar == matrix[row+1,col] &&
- currentChar == matrix[row+1,col+1])
- {
- count++;
- }
- }
- }
- Console.WriteLine(count);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment