Advertisement
Guest User

Problem 4

a guest
Jan 6th, 2013
1,035
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.98 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. class MaximumSeqEqual
  5. {
  6.     static void Main(string[] args)
  7.     {
  8.         int[] testArray = {2, 1, 1, 2, 3, 3, 2, 2, 2, 2, 1};
  9.         List<int> maximumSeqArray = new List<int>();
  10.         int start=0;
  11.         int length=1;
  12.         int bestStart=0;
  13.         int bestLength = 1;
  14.  
  15.         for (int i = 0; i < testArray.Length-1; i++)
  16.         {
  17.             if (testArray[i] == testArray[i + 1])
  18.             {
  19.                 length++;
  20.  
  21.                 if (length > bestLength)
  22.                 {
  23.                     bestLength = length;
  24.                     bestStart = start;
  25.                 }
  26.             }
  27.             else
  28.             {
  29.                 length = 1;
  30.                 start = i+1;
  31.             }
  32.         }
  33.  
  34.         for (int n = bestStart; n < bestStart + bestLength; n++)
  35.         {
  36.             maximumSeqArray.Add(testArray[n]);
  37.             Console.WriteLine("elements: {0}", testArray[n]);
  38.         }
  39.  
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement