Advertisement
Guest User

Untitled

a guest
Dec 26th, 2016
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.13 KB | None | 0 0
  1. private static void Main(string[] args)
  2.         {
  3.             int[,] array = { { 4, 0, 1 },
  4.                              { 3, 4, 5 },
  5.                              { 3, 5, 5 }
  6.                            };
  7.             int[] maxCount = new int[2];
  8.             var countElems = new Dictionary<int, int>(array.GetLength(0));
  9.             for (int i = 0; i < array.GetLength(0); i++)
  10.             {
  11.                 for (int j = 0; j < array.GetLength(1); j++)
  12.                 {
  13.                     if (!countElems.ContainsKey(array[i, j]))
  14.                     {
  15.                         countElems.Add(array[i, j], 1);
  16.                     }
  17.                     else
  18.                     {
  19.                         countElems[array[i, j]]++;
  20.                     }
  21.                     var maxSequence = countElems.Values.Max();
  22.                     if (maxCount[1] < maxSequence)
  23.                     {
  24.                         maxCount[0] = i;
  25.                         maxCount[1] = maxSequence;
  26.                     }
  27.                 }
  28.                 countElems.Clear();
  29.             }
  30.             Console.WriteLine(maxCount[0]);
  31.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement