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