Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- class Program
- {
- static void Main()
- {
- Console.WriteLine("Enter the size of the array:");
- int n = int.Parse(Console.ReadLine());
- int[] arr = new int[n];
- Console.WriteLine("Enter the {0} elements of the array:", n);
- for (int i = 0; i < n; i++)
- {
- arr[i] = int.Parse(Console.ReadLine());
- }
- List<int> seq = new List<int>();
- int tmp = 0;
- int biggest = 0;
- int seqLen = 1;
- int bestLen = 1;
- for (int i = 0; i < arr.Length; i++)
- {
- tmp = i;
- for (int j = i + 1; j < arr.Length; j++)
- {
- if (arr[j] < arr[tmp])
- {
- tmp = j;
- }
- }
- biggest = arr[tmp];
- arr[tmp] = arr[i];
- arr[i] = biggest;
- }
- for (int i = 0; i < n-1; i++)
- {
- if (arr[i] != arr[i + 1]) seqLen = 1;
- else
- {
- seqLen++;
- if (seqLen > bestLen)
- {
- bestLen = seqLen;
- seq.Clear();
- seq.Add(arr[i + 1]);
- }
- else if (seqLen == bestLen)
- {
- seq.Add(arr[i + 1]);
- }
- }
- }
- int[] sequence = seq.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