BSO90

Problem 9. Print Maximum Increasing Subsequence

May 19th, 2021
925
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.34 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Problem_9._Print_Maximum_Increasing_Subsequence
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             string[] input = Console.ReadLine().Split(' ');
  10.             int startIndex = -1;
  11.             int endIndex = -1;
  12.             int counter = 1;
  13.             int position = 1;
  14.             int maxCounter = 0;
  15.             for (int i = 0; i < input.Length; i++)
  16.             {
  17.                 int currNum = int.Parse(input[i]);
  18.                 if (currNum < int.Parse(input[position]))
  19.                 {
  20.                     counter++;
  21.                     if (counter >= maxCounter)
  22.                     {
  23.                         maxCounter = counter;
  24.                         endIndex = position;
  25.                     }
  26.                 }
  27.                    
  28.                 else
  29.                 {
  30.                     counter = 1;
  31.                 }
  32.  
  33.                 position++;
  34.                 if (position == input.Length)
  35.                 {
  36.                     break;
  37.                 }
  38.             }
  39.  
  40.             startIndex = endIndex - maxCounter + 1;
  41.             for (int i = startIndex; i <= endIndex; i++)
  42.             {
  43.                 Console.Write(input[i] + " ");
  44.             }
  45.         }
  46.     }
  47. }
  48.  
  49.                    
  50.                    
  51.                    
  52.  
Advertisement
Add Comment
Please, Sign In to add comment