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, 4, 5, 3, 4, 5, 6, 7, 8, 1, 1, 1, 1 };
- int beforeLastValueSequence = 0;
- int lengthSequence = 1;
- int maxLengthSequence = 1;
- for (int i = 0; i < array.Length - 1; i++)
- {
- if ((array[i] + 1) == array[i + 1])
- {
- lengthSequence += 1;
- if (lengthSequence > maxLengthSequence)
- {
- maxLengthSequence = lengthSequence;
- beforeLastValueSequence = 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} ", (beforeLastValueSequence + 2 - maxLengthSequence + i));
- }
- Console.WriteLine();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment