MiroslavKisov

MaxSequenceOfIncreasingElements

Oct 9th, 2017
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.14 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _07.MaxSequenceOfIncreasingElements
  5. {
  6.     public class StartUp
  7.     {
  8.         public static void Main()
  9.         {
  10.             long[] numbers = Console.ReadLine()
  11.                 .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  12.                 .Select(long.Parse)
  13.                 .ToArray();
  14.             int start = 0;
  15.             int bestStart = 0;
  16.             int length = 1;
  17.             int bestLength = 1;
  18.             for (int i = 0; i < numbers.Length - 1; i++)
  19.             {
  20.                 if (numbers[i] < numbers[i + 1])
  21.                 {
  22.                     length++;
  23.                     if (length > bestLength)
  24.                     {
  25.                         bestStart = start;
  26.                         bestLength = length;
  27.  
  28.                     }
  29.                 }
  30.                 else
  31.                 {
  32.                     start = i + 1;
  33.                     length = 1;
  34.                 }
  35.             }
  36.             for (int i = 0; i < bestLength; i++)
  37.             {
  38.                 Console.Write(numbers[bestStart + i] + " ");
  39.             }
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment