VelizarAvramov

07. Max Sequence of Increasing Elements

Nov 25th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.45 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _07._Max_Sequence_of_Increasing_Elements
  5. {
  6.     class MaxSeqIncreasingElements
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int[] array = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  11.            
  12.             int counter = 1;
  13.             int counterMax = 0;
  14.             int position = 0;
  15.  
  16.             for (int i = 0; i < array.Length - 1; i++)
  17.             {
  18.                 if (array[i] < array[i + 1])
  19.                 {
  20.                     counter++;
  21.                     if (counter > counterMax)
  22.                     {
  23.                         counterMax = counter;
  24.                         position = i + 1; ;
  25.                     }
  26.                 }
  27.                 else
  28.                 {
  29.                     counter = 1;
  30.                 }
  31.                 if (i + 1 == array.Length - 1)
  32.                 {
  33.                     if (counter > counterMax)
  34.                     {
  35.                         counterMax = counter;
  36.                         position = array[i];
  37.                     }
  38.                     counter = 1;
  39.                 }
  40.             }
  41.             int[] result = new int[counterMax];
  42.  
  43.             for (int i = 0; i < result.Length; i++)
  44.             {
  45.                 result[i] = array[position - counterMax + 1 + i];
  46.                 //position++;
  47.             }
  48.             Console.WriteLine(string.Join(" ",result));
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment