Advertisement
svetoslavbozov

[C#-2.1.5] MaxIncreasingSequence

Jan 6th, 2013
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.80 KB | None | 0 0
  1. using System;
  2.  
  3. class MaxIncreasingSequence
  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[] array = {1,2,3,5,6,8,9,0,1,4,5,6,7,8,1};
  13.  
  14.         for (int i = 0; i < array.Length - 1; i++)
  15.         {
  16.             if (array[i] < array[i + 1])
  17.             {
  18.                 count++;
  19.  
  20.                 if (count > newCount)
  21.                 {
  22.                     newCount = count;
  23.                     newStart = start;
  24.                 }
  25.             }
  26.             else
  27.             {
  28.                 count = 1;
  29.                 start = i + 1;
  30.             }
  31.         }
  32.  
  33.         for (int i = newStart; i < newStart + newCount; i++)
  34.         {
  35.             Console.Write(array[i] + " ");
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement