Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Write a program that finds the maximal sequence of equal elements in an array.
- Example: {2, 1, 1, 2, 3, 3, 2, 2, 2, 1} {2, 2, 2}. */
- using System;
- class MaxSequence
- {
- static void Main()
- {
- int[] array1 = new int[10] { 2, 1, 1, 2, 3, 3, 3, 2, 2, 1 };
- int counter = 0;
- int bigCounter = 0;
- int which1 = 0;
- for (int i = 0; i < array1.Length-1; i++)
- {
- if (array1[i] == array1[i + 1])
- {
- counter++;
- if (bigCounter <= counter)
- {
- bigCounter = counter;
- which1 = array1[i];
- }
- }
- else
- {
- counter = 0;
- }
- }
- Console.WriteLine("Longest streak is made of {0} consecutive {1}'s",bigCounter+1, which1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement