petarkobakov

Squares in Matrix

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