Guest User

Untitled

a guest
Apr 22nd, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.15 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. class Program {
  5.  
  6.     static bool checkNeightbour (int rows, int columns, int x, int y) {
  7.         bool inRow    = x >= 0 && x < rows;
  8.         bool inColumn = y >= 0 && y < columns;
  9.         return inRow && inColumn;
  10.     }
  11.  
  12.     static List<int> neightbours (int[,] matrix, int rows, int columns, int x, int y) {
  13.         List<int> lst = new List<int> ();
  14.         for (int i = x - 1; i <= x + 1; i++)
  15.             for (int j = y - 1; j <= y + 1; j++)
  16.                 if (checkNeightbour (rows, columns, i, j))
  17.                     lst.Add (matrix[i, j]);
  18.         return lst;
  19.     }
  20.  
  21.     static bool localMinimum (int[,] matrix, int rows, int columns, int x, int y) {
  22.         int element = matrix[x,y];
  23.         List<int> neightboursList = neightbours (matrix, rows, columns, x, y);
  24.         for (int i = 0; i < neightboursList.Count; i++)
  25.             if (neightboursList[i] <= element)
  26.                 return false;
  27.         return true;
  28.     }
  29.  
  30.     static int countLocalMinimums (int[,] matrix, int rows, int columns) {
  31.         int count = 0;
  32.         for (int i = 0; i < rows; i++)
  33.             for (int j = 0; j < columns; j++)
  34.                 if (localMinimum (matrix, rows, columns, i, j)
  35.                     count++;
  36.         return count;
  37.     }
  38.  
  39.     static void Main (string[] args) {
  40.        
  41.     }
  42. }
Add Comment
Please, Sign In to add comment