Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- class Program {
- static bool checkNeightbour (int rows, int columns, int x, int y) {
- bool inRow = x >= 0 && x < rows;
- bool inColumn = y >= 0 && y < columns;
- return inRow && inColumn;
- }
- static List<int> neightbours (int[,] matrix, int rows, int columns, int x, int y) {
- List<int> lst = new List<int> ();
- for (int i = x - 1; i <= x + 1; i++)
- for (int j = y - 1; j <= y + 1; j++)
- if (checkNeightbour (rows, columns, i, j))
- lst.Add (matrix[i, j]);
- return lst;
- }
- static bool localMinimum (int[,] matrix, int rows, int columns, int x, int y) {
- int element = matrix[x,y];
- List<int> neightboursList = neightbours (matrix, rows, columns, x, y);
- for (int i = 0; i < neightboursList.Count; i++)
- if (neightboursList[i] <= element)
- return false;
- return true;
- }
- static int countLocalMinimums (int[,] matrix, int rows, int columns) {
- int count = 0;
- for (int i = 0; i < rows; i++)
- for (int j = 0; j < columns; j++)
- if (localMinimum (matrix, rows, columns, i, j)
- count++;
- return count;
- }
- static void Main (string[] args) {
- }
- }
Add Comment
Please, Sign In to add comment