Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace TEST
- {
- class Program
- {
- static void Main()
- {
- Console.Write("Enter the Length of Array: ");
- int n = int.Parse(Console.ReadLine());
- int[] myArray = new int[n];
- for (int i = 0; i < n; i++)
- {
- Console.Write("Enter array[{0}] = ",i);
- myArray[i] = int.Parse(Console.ReadLine());
- }
- int len = 1;
- int BestLen = 0;
- int index = 0;
- for (int i = 0; i < myArray.Length - 1; i++)
- {
- if (myArray[i] == myArray[i + 1])
- {
- len++;
- if (len > BestLen)
- {
- BestLen = len;
- index = myArray[i];
- }
- }
- else
- {
- len = 1;
- }
- }
- if (BestLen == 0)
- {
- Console.WriteLine("No sequence!");
- return;
- }
- Console.WriteLine("Number {0} Repeats {1} times", index, BestLen);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment