Advertisement
martinvalchev

Max_Sequence_of_Increasing_Elements

Feb 7th, 2018
89
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 Max_Sequence_of_Increasing_Elements
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int[] arr = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  11.             int counter = 1;
  12.             int counterMax = 0;
  13.             int position = 0;
  14.  
  15.             for (int i = 0; i < arr.Length - 1; i++)
  16.             {
  17.                 if (arr[i] < arr[i + 1])
  18.                 {
  19.                     counter++;
  20.                     if (counter > counterMax)
  21.                     {
  22.                         counterMax = counter;
  23.                         position = i + 1;
  24.                     }
  25.                 }
  26.                 else
  27.                 {
  28.                     counter = 1;
  29.                 }
  30.                 }
  31.  
  32.  
  33.                 int[] result = new int[counterMax];
  34.                 for (int i = 0; i < result.Length; i++)
  35.                 {
  36.                     result[i] = arr[position - counterMax + 1];
  37.                     position++;
  38.                 }
  39.                 Console.WriteLine(string.Join(" ",result));
  40.  
  41.             }
  42.         }
  43.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement