Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- class MaxSeqOfIncreasingElements
- {
- static void Main()
- {
- int[] seq = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
- int value;
- var maximumSequence = MaximimalSequence<int>(new List<int>(seq.ToList()), out value);
- for (int i = 0; i < maximumSequence; i++)
- {
- Console.Write(value + " ");
- }
- }
- public static int MaximimalSequence<T>(IList<T> list, out T value)
- {
- T aux = default(T);
- value = default(T);
- int max = 0, hist = 0;
- bool first = true;
- foreach (var i in list)
- {
- if (!first && aux.Equals(i))
- {
- max++;
- }
- else
- {
- first = false;
- max = 1;
- }
- if (hist < max)
- {
- hist = max;
- value = i;
- }
- aux = i;
- }
- return hist;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement