Advertisement
Guest User

07. Max Sequence of Increasing Elements

a guest
Jun 3rd, 2018
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.97 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace temp
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int[] nums = Console.ReadLine().Split().Select(int.Parse).ToArray();
  12.  
  13.             int firstPosition = 0;
  14.             int length = 1;
  15.             long maxLength = 0;
  16.  
  17.             for (int i = nums.Length - 1; i > 0; i--)
  18.             {
  19.  
  20.                 if (nums[i] - nums[i - 1] >= 1)
  21.                 {
  22.                     length++;
  23.                 }
  24.                 else
  25.                 {
  26.                     length = 1;
  27.                 }
  28.                 if (length >= maxLength)
  29.                 {
  30.                     maxLength = length;
  31.                     firstPosition = i - 1;
  32.                 }
  33.  
  34.             }
  35.  
  36.             for (int i = firstPosition; i < maxLength + firstPosition; i++)
  37.             {
  38.                 Console.Write(nums[i] + " ");
  39.             }
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement