Advertisement
ivan_yosifov

Maximal_Sequence

Dec 13th, 2013
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.10 KB | None | 0 0
  1. using System;
  2.  
  3. class MaximalSequence
  4. {
  5.     static void InitializeArray(int[] arr)
  6.     {
  7.         for (int i = 0; i < arr.Length; i++)
  8.         {
  9.             Console.Write("Enter {0} element: ", i + 1);
  10.             arr[i] = int.Parse(Console.ReadLine());
  11.         }
  12.     }
  13.     static void Main()
  14.     {
  15.         int total = 0;
  16.         Console.Write("Enter number of elements: ");
  17.         total = int.Parse(Console.ReadLine());
  18.         int[] array = new int[total];
  19.         InitializeArray(array);
  20.  
  21.  
  22.         int current = 0;
  23.         int prev = 0;
  24.         int count = 0;
  25.         int maximalCount = 0;
  26.         for (int i = 0; i < array.Length; i++)
  27.         {
  28.             current = array[i];
  29.             if (i == 0)
  30.             {
  31.                 prev = current;
  32.             }
  33.             else
  34.             {
  35.                 prev = array[i - 1];
  36.             }
  37.             if (current == prev) count++;
  38.             else count = 1;
  39.             if (count > maximalCount)
  40.             {
  41.                 maximalCount = count;
  42.             }
  43.         }
  44.         Console.WriteLine(maximalCount);
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement