Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2020
80
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. namespace _2x2SquaresInMatrix
  4. {
  5. class Program
  6. {
  7. static void inputMatrix(int rows, int cows, char[,] matrix)
  8. {
  9. for (int i = 0; i < rows; i++)
  10. {
  11. char[] row = Console.ReadLine().Split(new[] { ' '},StringSplitOptions.RemoveEmptyEntries).Select(char.Parse).ToArray();
  12. for (int j = 0; j < cows; j++)
  13. {
  14. matrix[i, j] = row[j];
  15. }
  16. }
  17. }
  18. static void Main(string[] args)
  19. {
  20. int counter = 0;
  21. int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
  22. if(input.Length!=2)
  23. {
  24. return;
  25. }
  26. int rows = input[0];
  27. int cows = input[1];
  28. char[,] matrix = new char[rows, cows];
  29. inputMatrix(rows, cows, matrix);
  30. for (int i = 0; i < rows - 1; i++)
  31. {
  32. for (int j = 0; j < cows - 1; j++)
  33. {
  34. if (matrix[i, j] == matrix[i + 1, j] && matrix[i, j] == matrix[i , j+1] && matrix[i, j] == matrix[i + 1, j + 1])
  35. {
  36. counter++;
  37. }
  38. }
  39. }
  40. Console.WriteLine(counter);
  41.  
  42. }
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement