Advertisement
svetoslavbozov

[C#-2.1.4] MaxSequence

Jan 6th, 2013
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.95 KB | None | 0 0
  1. using System;
  2.  
  3. class MaxSequence
  4. {
  5.     static void Main()
  6.     {
  7.         int start = 0;
  8.         int newStart = 0;
  9.         int count = 1;
  10.         int newCount = 1;
  11.  
  12.         int n = int.Parse(Console.ReadLine());
  13.  
  14.         int[] array = new int[n];
  15.  
  16.         for (int i = 0; i < n; i++)
  17.         {
  18.             array[i] = int.Parse(Console.ReadLine());
  19.         }
  20.  
  21.         for (int i = 0; i < array.Length - 1; i++)
  22.         {
  23.             if (array[i] == array[i + 1])
  24.             {
  25.                 count++;
  26.  
  27.                 if (count > newCount)
  28.                 {
  29.                     newCount= count;
  30.                     newStart = start;
  31.                 }
  32.             }
  33.             else
  34.             {
  35.                 count = 1;
  36.                 start = i + 1;
  37.             }
  38.         }
  39.  
  40.         for (int i = newStart; i < newStart + newCount; i++)
  41.         {            
  42.             Console.Write(array[i] + " ");          
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement