Advertisement
Guest User

Untitled

a guest
Oct 12th, 2017
427
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.21 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _07.Max_Sequence_of_Increasing_Elements
  5. {
  6.     class Program
  7.     {
  8.         static void Main()
  9.         {
  10.             int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();
  11.  
  12.             int longestSeq = 0;
  13.             int counter = 0;
  14.             int endIndex = 0;
  15.  
  16.             for (int i = 1; i < input.Length; i++)
  17.             {
  18.                 if (input[i - 1] < input[i])
  19.                 {
  20.                     counter++;
  21.                 }
  22.                 else
  23.                 {
  24.                     if (counter > longestSeq)
  25.                     {
  26.                         longestSeq = counter;
  27.                         endIndex = i - 1;
  28.                     }
  29.                     counter = 0;
  30.                 }
  31.                 if (i == input.Length - 1)
  32.                 {
  33.                     if (counter > longestSeq)
  34.                     {
  35.                         longestSeq = counter;
  36.                         endIndex = i;
  37.                     }
  38.                 }
  39.             }
  40.             for (int i = endIndex - longestSeq; i <= endIndex; i++)
  41.             {
  42.                 Console.Write(input[i] + " ");
  43.             }
  44.         }
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement