Advertisement
PolinaKoleva

MaximalIncreasingSequence

Jan 12th, 2013
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.17 KB | None | 0 0
  1. using System;
  2. class Problem5MaxIncreasingSequence
  3. {
  4.     static void Main()
  5.     {
  6.         int size = int.Parse(Console.ReadLine());
  7.         int[] arr = new int[size];
  8.         int max = 1;
  9.         int count = 1;
  10.         int start = 0;
  11.         for (int i = 0; i < arr.Length; i++)
  12.         {
  13.             arr[i] = int.Parse(Console.ReadLine());
  14.         }
  15.         for (int i = 0; i < arr.Length-1; i++)
  16.         {
  17.             if(arr[i]+1 == arr[i+1])
  18.             {
  19.                 count++;
  20.                 if (count > max)
  21.                 {
  22.                     max = count;
  23.                     start = arr[i+1];
  24.                 }
  25.             }
  26.             else
  27.             {
  28.                 count = 1;
  29.             }
  30.         }
  31.         if (max == 1)
  32.         {
  33.             Console.WriteLine("This sequence doesn`t have a maximal sequence of increasing elements. ");
  34.         }
  35.         else
  36.         {
  37.             Console.Write("The maximal sequence of increasing elements is: " + max + ": ");
  38.             for (int i = max; i > 0; i--)
  39.             {
  40.                 Console.Write((start-i + 1) + " ");
  41.             }
  42.             Console.WriteLine();
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement