Advertisement
bacco

Max Sequence of Increasing Elements

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