Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace _04.MaximalSequence
- {
- class MaximalSequence
- {
- static void Main(string[] args)
- {
- Console.Write("Length of sequence = ");
- int arraySize = int.Parse(Console.ReadLine());
- int[] array = new int[arraySize];
- for (int i = 0; i < arraySize; i++)
- {
- Console.Write("element[{0}]: ", i + 1);
- array[i] = int.Parse(Console.ReadLine());
- }
- int start = 0;
- int length = 1;
- int maxlength = 0;
- for (int i = 1; i < array.Length; i++)
- {
- if (array[i - 1] == array[i])
- {
- length++;
- if (length > maxlength)
- {
- maxlength = length;
- start = array[i];
- }
- }
- else
- {
- length = 1;
- }
- }
- Console.Write("The maximal sequence of equal elements is: { ");
- for (int i = 0; i < maxlength; i++)
- {
- Console.Write(start + " ");
- }
- Console.WriteLine("}");
- Console.WriteLine("Sequentially repeated {0} times", maxlength);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement