Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- class MaxSequenceOfEqualElements
- {
- static void Main()
- {
- decimal[] nums = Console.ReadLine().Split().Select(decimal.Parse).ToArray();
- List<List<decimal>> sequences = new List<List<decimal>>();
- List<decimal> sequence = new List<decimal>();
- int start = 0;
- int end = 0;
- for (int i = 1; i < nums.Length; i++)
- {
- if (nums[i - 1] == nums[i])
- {
- end++;
- }
- else if (end > 0)
- {
- start = i - end - 1;
- end = i - 1;
- AddSequence(nums, ref start, ref end, sequences, sequence);
- sequence = new List<decimal>();
- }
- if (i == nums.Length - 1 && end > 0)
- {
- start = i - end;
- end = i;
- AddSequence(nums, ref start, ref end, sequences, sequence);
- sequence = new List<decimal>();
- }
- }
- decimal max = decimal.MinValue;
- for (int i = 0; i < sequences.Count; i++)
- {
- if (max < sequences[i].Count)
- {
- max = sequences[i].Count;
- }
- }
- foreach (var item in sequences)
- {
- if (item.Count == max)
- {
- Console.WriteLine(String.Join(" ", item));
- break;
- }
- }
- }
- private static void AddSequence(decimal[] nums, ref int start, ref int end, List<List<decimal>>sequences, List<decimal> sequence)
- {
- for (int a = start; a <= end; a++)
- {
- sequence.Add(nums[a]);
- }
- sequences.Add(sequence);
- start = 0;
- end = 0;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment