Advertisement
simonses

MaxIncreasSequence

Jan 9th, 2013
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.22 KB | None | 0 0
  1. using System;
  2.  
  3. class MaxIncreasSequence
  4. {
  5.     static void Main()
  6.     {
  7.         Console.WriteLine("Please, Insert the length of the array!");
  8.         int n = int.Parse(Console.ReadLine());
  9.  
  10.         // Read the array
  11.         int[] array = new int[n];
  12.  
  13.         for (int i = 0; i < n; i++)
  14.         {
  15.             array[i] = int.Parse(Console.ReadLine());
  16.         }
  17.  
  18.         // Compair
  19.         int count = 0;
  20.         int maxLength = 0;
  21.         int getPossition = 0;
  22.  
  23.         for (int i = 0; i < array.Length - 1; i++)
  24.         {
  25.             if ((array[i] + 1) == (array[i + 1])) // if the condition of the task is "+1"
  26.  
  27.             // if (array[i] <= array[i + 1]) // if the condition of the task is "increese sequence"
  28.             {
  29.                 count++;
  30.             }
  31.             else
  32.             {
  33.                 count = 0;
  34.             }
  35.             if (count >= maxLength)
  36.             {
  37.                 maxLength = count;
  38.                 getPossition = i + 1 - count;
  39.             }
  40.         }
  41.         maxLength += 1;
  42.  
  43.         // Print
  44.         for (int i = getPossition; i < getPossition + maxLength; i++)
  45.         {
  46.             Console.Write(array[i] + " ");
  47.         }
  48.         Console.WriteLine();
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement