Advertisement
vlad0

help arrays 5

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