Advertisement
Naralex

MaximalIncreasingSequence

Jan 13th, 2013
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.24 KB | None | 0 0
  1. using System;
  2.  
  3. class MaximalIncreasingSequence
  4. {
  5. static void Main()
  6. {
  7.         Console.Write("Type in the size of the Array: ");
  8.         int arraySize = int.Parse(Console.ReadLine());
  9.         int[] arr = new int[arraySize];
  10.  
  11.         int arrayValue, startNumber = 0,count = 0, bestCount = 0;
  12.         string sequence = " ", bestSequence = " ";
  13.  
  14.         for (int index = 0; index < arraySize; index++)
  15.         {
  16.             Console.Write("Position [{0}]: ", index);
  17.             arrayValue = int.Parse(Console.ReadLine());
  18.             arr[index] = arrayValue;
  19.         }
  20.  
  21.         for (int i = 0; i < arr.Length; i++)
  22.         {
  23.             if (startNumber < arr[i])
  24.             {
  25.                 count++;
  26.                 startNumber = arr[i];
  27.  
  28.                 if (count >= bestCount)
  29.                 {
  30.                     bestCount = count;
  31.                     sequence += arr[i] + " ";
  32.                     bestSequence = sequence;
  33.                 }
  34.             }
  35.             else if (startNumber >= arr[i])
  36.             {
  37.                 startNumber = arr[i];
  38.                 sequence = " ";
  39.                 sequence += arr[i] + " ";
  40.                 count = 1;
  41.             }
  42.         }
  43.         Console.WriteLine(bestSequence);
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement