SHARE
TWEET

Maximal increasing Sequence

a guest Nov 19th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _09._Print_Maximum_Increasing_Subsequence
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             List<int> numbers = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
  12.             List<int> currentSequence = new List<int>();
  13.             List<int> longestSequence = new List<int>();
  14.  
  15.                 for (int j = 0; j < (numbers.Count-1); j++)
  16.                 {
  17.                     if (numbers[j]<numbers[j+1])
  18.                     {
  19.                         currentSequence.Add(numbers[j]);
  20.                     }
  21.                     else if (currentSequence.Count>=longestSequence.Count)
  22.                     {
  23.                         longestSequence.Clear();
  24.                         longestSequence = currentSequence;
  25.                         currentSequence.Clear();
  26.                     }
  27.                     else if (numbers[j] > numbers[j+1])
  28.                     {
  29.                         currentSequence.Clear();
  30.                     }
  31.                 }              
  32.            
  33.             Console.WriteLine(String.Join(" ",longestSequence));
  34.  
  35.         }
  36.     }
  37. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top