Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- namespace _02_SquaresInMatrix
- {
- class Program
- {
- static void Main(string[] args)
- {
- var sizes = Console.ReadLine()
- .Split()
- .Select(int.Parse)
- .ToArray();
- var rows = sizes[0];
- var cols = sizes[1];
- var matrix = new char[rows, cols];
- var numOfSquares = 0;
- for (int r = 0; r < matrix.GetLength(0); r++)
- {
- var chars = Console.ReadLine()
- .Split()
- .Select(char.Parse)
- .ToArray();
- for (int c = 0; c < matrix.GetLength(1); c++)
- {
- matrix[r, c] = chars[c];
- }
- }
- for (int r = 0; r < matrix.GetLength(0) - 1; r++)
- {
- for (int c = 0; c < matrix.GetLength(1) - 1; c++)
- {
- if (matrix[r, c] == matrix[r, c + 1]
- && matrix[r, c] == matrix[r + 1, c]
- && matrix[r, c] == matrix[r + 1, c + 1])
- {
- numOfSquares++;
- }
- }
- }
- Console.WriteLine(numOfSquares);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement