Advertisement
bacco

Max Sequence of Increasing Elements

May 6th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.10 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace test
  6. {
  7.     class MainClass
  8.     {
  9.         public static void Main()
  10.         {
  11.  
  12.             int[] arr = Console.ReadLine()
  13.                                       .Split(' ')
  14.                                         .Select(int.Parse)
  15.                                           .ToArray();
  16.             var counter = 1;
  17.             var maxCounter = 0;
  18.             var position = 0;
  19.  
  20.             for (int i = 0; i < arr.Length - 1; i++)
  21.             {
  22.                 if (arr[i] < arr[i + 1])
  23.                 {
  24.                     counter++;
  25.  
  26.                     if (maxCounter < counter)
  27.                     {
  28.                         maxCounter = counter;
  29.                         position = i + 1;
  30.                     }
  31.                 }
  32.                 else
  33.                 {
  34.                     counter = 1;
  35.                 }
  36.             }
  37.  
  38.             for (int i = 0; i < maxCounter; i++)
  39.             {
  40.                 Console.Write(arr[position - maxCounter + 1 + i] + " ");
  41.             }
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement