Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class Program
- {
- static void Main(string[] args)
- {
- int[] array = { 1, 1, 2, 2, 2, 3, 3, 2, 2, 1, 1, 1, 1 };
- int valueSequence = 0;
- int lengthSequence = 1;
- int maxLengthSequence = 1;
- for (int i = 0; i < array.Length-1; i++)
- {
- if (array[i] == array[i+1])
- {
- lengthSequence += 1;
- if (lengthSequence > maxLengthSequence)
- {
- maxLengthSequence = lengthSequence;
- valueSequence = array[i];
- }
- }
- else
- {
- lengthSequence = 1;
- }
- }
- Console.Write("The maximum sequence of equal elements in an array is: ");
- for (int i = 0; i < maxLengthSequence; i++)
- {
- Console.Write("{0} ",valueSequence);
- }
- Console.WriteLine();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment