Advertisement
Teodor92

MultiArray.2.MaxSumArea

Jan 22nd, 2013
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.05 KB | None | 0 0
  1. using System;
  2.  
  3. class MaxSumArea
  4. {
  5.     static void Main()
  6.     {
  7.         int[,] matrix = {
  8.         {1,1,1,1,1},
  9.         {1,1,1,1,1},
  10.         {1,1,1,1,2}
  11.         };
  12.         int bestSum = int.MinValue;
  13.         for (int rows = 0; rows < matrix.GetLength(0) - 2; rows++)
  14.         {
  15.             for (int cols = 0; cols < matrix.GetLength(1) - 2; cols++)
  16.             {
  17.                 //3x3 checker
  18.                 // * * * - -
  19.                 // * * * - -
  20.                 // * * * - -
  21.                 int currentSum = 0;
  22.                 for (int newRow = rows; newRow < rows + 3; newRow++)
  23.                 {
  24.                     for (int newCol = cols; newCol < cols + 3; newCol++)
  25.                     {
  26.                         currentSum = currentSum + matrix[newRow, newCol];
  27.                     }
  28.                 }
  29.                 // best sum check
  30.                 if (bestSum <= currentSum)
  31.                 {
  32.                     bestSum = currentSum;
  33.                 }
  34.             }
  35.         }
  36.         Console.WriteLine(bestSum);
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement