Advertisement
llhewitt

Untitled

Dec 21st, 2013
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.78 KB | None | 0 0
  1. using System;
  2.  
  3. class MaxSequenceOfEqualElements
  4. {
  5.     static void Main()
  6.     {
  7.         int[] arr = { 2, 1, 1, 2, 3, 3, 2, 2, 2, 1 };
  8.         int start = 0;
  9.         int len = 1;
  10.         int bestStart = 0;
  11.         int bestLen = 1;
  12.  
  13.         for (int i = 0; i <= arr.Length - 1; i++)
  14.         {
  15.             if (arr[i + 1] == arr[i])
  16.             {
  17.                 len++;
  18.                 if (bestLen<len)
  19.                 {
  20.                     bestLen = len;
  21.                     bestStart = start;
  22.                 }
  23.             }
  24.             else
  25.             {
  26.                 start = i + 1;
  27.                 len = 1;
  28.             }
  29.         }
  30.         for (int n = bestStart; n < bestStart + bestLen; n++)
  31.         {
  32.             Console.WriteLine(arr[n]);
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement