Advertisement
simonses

3taArrays

Jan 18th, 2013
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.54 KB | None | 0 0
  1. using System;
  2.  
  3. class MatrixBiggerSum
  4. {
  5.     static void Main()
  6.     {
  7.         string[,] matrix = {
  8.             {"ha", "hifi", "ho", "hi"},
  9.             {"fo", "ha", "fi", "ha"},
  10.             {"xxx", "ho", "ha", "xx"},
  11.         };
  12.         //string[,] matrix = {
  13.         //    {"s", "qq", "s"},
  14.         //    {"pp", "pp", "s"},
  15.         //    {"pp", "qq", "s"},
  16.         //};
  17.  
  18.         int countVertical = 0;
  19.         int countHorizontal = 0;
  20.         int countDiagonalLeftUp = 0;
  21.         int countDiagoanlRightUp = 0;
  22.         string strVertical = null;
  23.         string strHorizontal = null;
  24.         string strDiagonalLeftUp = null;
  25.         string strDiagonalRightUp = null;
  26.  
  27.         // Vertical - row
  28.         for (int row = 0; row <
  29.             matrix.GetLength(0); row++)
  30.         {
  31.             int currentCount = 0;
  32.             for (int col = 0; col < matrix.GetLength(1) - 1; col++)
  33.             {
  34.                 if (matrix[row, col] == matrix[row, col + 1])
  35.                 {
  36.                     currentCount++;
  37.                 }
  38.                 else
  39.                 {
  40.                     currentCount = 0;
  41.                 }
  42.                 if (countVertical < currentCount)
  43.                 {
  44.                     countVertical = currentCount;
  45.                     strVertical = matrix[row, col];
  46.                 }
  47.             }
  48.         }
  49.  
  50.         // Print the result
  51.         Console.WriteLine("It is:");
  52.  
  53.         for (int i = 0; i <= countVertical; i++)
  54.         {
  55.             Console.Write(strVertical + " ");
  56.         }
  57.  
  58.     }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement