Advertisement
vaakata

Max Sequence of Increasing Elements

May 13th, 2016
675
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.37 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace MaxSeqInc_13._05._2016
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int[] numbers = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
  14.             int l = numbers.Length;
  15.  
  16.             MaxIncSequence(numbers, l);
  17.         }
  18.  
  19.         static void MaxIncSequence(int[] numbers, int l)
  20.         {
  21.             int cntCurrSeq = 0;
  22.             int startCurrSeq = 0;
  23.             int cntMaxSeq = 0;
  24.             int startMaxSeq = 0;
  25.  
  26.             for (int i = 1; i < l; i++)
  27.             {
  28.                 if (numbers[i] - numbers[i - 1] == 1)
  29.                 {
  30.                     cntCurrSeq++;
  31.                     startCurrSeq = i - cntCurrSeq;
  32.  
  33.                     if (cntCurrSeq > cntMaxSeq)
  34.                     {
  35.                         cntMaxSeq = cntCurrSeq;
  36.                         startMaxSeq = startCurrSeq;
  37.                     }
  38.                 }
  39.                 else
  40.                 {
  41.                     cntCurrSeq = 0;
  42.                 }
  43.             }
  44.             for (int iWrite = startMaxSeq; iWrite <= (startMaxSeq + cntMaxSeq); iWrite++)
  45.             {
  46.                 Console.Write(numbers[iWrite] + " ");
  47.             }
  48.             Console.WriteLine();
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement