Advertisement
Guest User

Untitled

a guest
Jul 10th, 2013
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.37 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _04.MaximalSequence
  4. {
  5.     class MaximalSequence
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.                Console.Write("Length of sequence = ");
  10.             int arraySize = int.Parse(Console.ReadLine());
  11.             int[] array = new int[arraySize];
  12.          
  13.             for (int i = 0; i < arraySize; i++)
  14.             {
  15.                 Console.Write("element[{0}]: ", i + 1);
  16.                 array[i] = int.Parse(Console.ReadLine());
  17.             }
  18.             int start = 0;
  19.             int length = 1;
  20.             int maxlength = 0;
  21.             for (int i = 1; i < array.Length; i++)
  22.             {
  23.                 if (array[i - 1] == array[i])
  24.                 {
  25.                     length++;
  26.                     if (length > maxlength)
  27.                     {
  28.                         maxlength = length;
  29.                         start = array[i];
  30.                     }
  31.                 }
  32.                 else
  33.                 {
  34.                     length = 1;
  35.                 }
  36.             }
  37.             Console.Write("The maximal sequence of equal elements is: { ");
  38.             for (int i = 0; i < maxlength; i++)
  39.             {
  40.                 Console.Write(start + " ");
  41.             }
  42.             Console.WriteLine("}");
  43.             Console.WriteLine("Sequentially repeated {0} times", maxlength);
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement