Advertisement
fbinnzhivko

Untitled

Jun 5th, 2016
107
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.Collections.Generic;
  3. using System.Linq;
  4. class MaxSeqOfIncreasingElements
  5. {
  6.     static void Main()
  7.     {
  8.  
  9.         int[] seq = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
  10.         int value;
  11.         var maximumSequence = MaximimalSequence<int>(new List<int>(seq.ToList()), out value);
  12.  
  13.         for (int i = 0; i < maximumSequence; i++)
  14.         {
  15.             Console.Write(value + " ");
  16.         }
  17.     }
  18.  
  19.     public static int MaximimalSequence<T>(IList<T> list, out T value)
  20.     {
  21.         T aux = default(T);
  22.         value = default(T);
  23.         int max = 0, hist = 0;
  24.         bool first = true;
  25.  
  26.         foreach (var i in list)
  27.         {
  28.             if (!first && aux.Equals(i))
  29.             {
  30.                 max++;
  31.             }
  32.             else
  33.             {
  34.                 first = false;
  35.                 max = 1;
  36.             }
  37.             if (hist < max)
  38.             {
  39.                 hist = max;
  40.                 value = i;
  41.             }
  42.             aux = i;
  43.         }
  44.         return hist;
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement