Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- class FindMaxSeq_04
- {
- static void Main()
- {
- int n = int.Parse(Console.ReadLine());
- int[] arr = new int[n];
- for (int i = 0; i < n; i++)
- {
- arr[i] = int.Parse(Console.ReadLine());
- }
- List<int> listSeq = new List<int>();
- int seqLen = 1;
- int bestLen = 1;
- for (int i = 0; i < n-1; i++)
- {
- if (arr[i] != arr[i + 1]) seqLen = 1;
- else
- {
- seqLen++;
- if (seqLen > bestLen)
- {
- bestLen = seqLen;
- listSeq.Clear();
- listSeq.Add(arr[i + 1]);
- }
- else if (seqLen == bestLen)
- {
- listSeq.Add(arr[i + 1]);
- }
- }
- }
- int[] sequence = listSeq.ToArray();
- int seqLength = sequence.Length;
- string result = "";
- for (int m = 0; m < seqLength; m++)
- {
- for (int j = 0; j < bestLen; j++)
- {
- result += sequence[m] + " ";
- }
- }
- if (bestLen <= 1)
- {
- Console.WriteLine("No sequence found!");
- }
- else Console.WriteLine("The maximal sequence of equal elements is " + bestLen + ":" + result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment