GabrielDas

Untitled

May 22nd, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace P02SquaresInMatrix
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. int[] arr = Console.ReadLine().Split(" ").Select(int.Parse).ToArray();
  11.  
  12. int rows = arr[0];
  13. int cols = arr[1];
  14. int count = 0;
  15.  
  16. var matrix = new char[rows, cols];
  17.  
  18. for (int row = 0; row < matrix.GetLength(0); row++)
  19. {
  20. char[] letters = Console.ReadLine()
  21. .Split(" ", StringSplitOptions.RemoveEmptyEntries)
  22. .Select(char.Parse)
  23. .ToArray();
  24.  
  25. for (int col = 0; col < matrix.GetLength(1); col++)
  26. {
  27. matrix[row, col] = letters[col];
  28.  
  29.  
  30. }
  31. }
  32.  
  33. for (int i = 0; i < matrix.GetLength(0)-1; i++)
  34. {
  35.  
  36. for (int j = 0; j < matrix.GetLength(1)-1; j++)
  37. {
  38.  
  39. if(matrix[i, j] == matrix[i, j+1]
  40. && matrix[i,j+1] == matrix [i+1,j]
  41. && matrix[i+1,j] == matrix[i + 1, j + 1])
  42. {
  43. count++;
  44. }
  45.  
  46.  
  47. }
  48. }
  49.  
  50. Console.WriteLine(count);
  51.  
  52. }
  53. }
  54. }
Add Comment
Please, Sign In to add comment