Advertisement
ScorpS

Maximal Increasing Sequences In Array

Jan 6th, 2013
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 KB | None | 0 0
  1.  
  2. //Write a program that finds the maximal increasing sequence
  3. //in an array. Example: {3, 2, 3, 4, 2, 2, 4}  {2, 3, 4}.
  4.  
  5.  
  6. using System;
  7.  
  8. class MaximalIncreasingSequencesInArray
  9. {
  10.     static void Main()
  11.     {
  12.         int[] array = new int[10];
  13.         int counter = 1;
  14.         int count = 0;
  15.         int firstNumber = 0;
  16.  
  17.  
  18.         for (int index = 0; index < 10; index++)
  19.         {
  20.             array[index] = int.Parse(Console.ReadLine());
  21.         }
  22.  
  23.         for (int index = 0; index < 9; index++)
  24.         {
  25.             if (array[index] + 1 == array[index + 1])
  26.             {
  27.                 counter++;
  28.             }
  29.             else
  30.             {
  31.                 counter = 1;
  32.             }
  33.  
  34.             if (count < counter)
  35.             {
  36.                 count = counter;
  37.                 firstNumber = array[index] + 1;
  38.             }
  39.         }
  40.  
  41.         for (int i = count - 1; i >= 0; i--)
  42.         {
  43.             Console.Write((firstNumber - i) + ", ");
  44.         }
  45.  
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement