nKolchakoV

FindMaxSequence

Dec 7th, 2013
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.36 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace TEST
  8. {
  9.     class Program
  10.     {
  11.         static void Main()
  12.         {
  13.  
  14.             Console.Write("Enter the Length of Array: ");
  15.             int n = int.Parse(Console.ReadLine());
  16.             int[] myArray = new int[n];
  17.            
  18.             for (int i = 0; i < n; i++)
  19.             {
  20.                 Console.Write("Enter array[{0}] = ",i);
  21.                 myArray[i] = int.Parse(Console.ReadLine());
  22.             }
  23.  
  24.             int len = 1;
  25.             int BestLen = 0;
  26.             int index = 0;
  27.             for (int i = 0; i < myArray.Length - 1; i++)
  28.             {
  29.                
  30.                 if (myArray[i] == myArray[i + 1])
  31.                 {
  32.                     len++;
  33.                     if (len > BestLen)
  34.                     {
  35.                         BestLen = len;
  36.                         index = myArray[i];
  37.  
  38.                     }
  39.  
  40.                 }
  41.  
  42.                 else
  43.                 {
  44.                     len = 1;
  45.                 }
  46.             }
  47.             if (BestLen == 0)
  48.             {
  49.                 Console.WriteLine("No sequence!");
  50.                 return;
  51.             }
  52.            
  53.             Console.WriteLine("Number {0} Repeats {1} times", index, BestLen);
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment