Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace FindMaxSequenceOfEqualElements
- {
- class Program
- {
- static void Main(string[] args)
- {
- //Write a program that finds the maximal sequence of equal elements in an array.
- Console.WriteLine("Please enter numbers of elements of the array: ");
- int n = int.Parse(Console.ReadLine());
- int[] array = new int[n];
- int count = 1;
- int max = 0;
- int number = 0;
- int bigLenght = 0;
- Console.WriteLine("Please enter elements of the array: ");
- for (int i = 0; i < n; i++)
- {
- array[i] = int.Parse(Console.ReadLine());
- }
- for (int i = 0; i < n-1; i++)
- {
- if (array[i] == array[i + 1])
- {
- count += 1;
- max = array[i];
- }
- else
- {
- count = 1;
- }
- if (count > bigLenght)
- {
- number = max;
- bigLenght = count;
- }
- }
- Console.WriteLine();
- for (int i = 0; i < bigLenght; i++)
- {
- if (bigLenght != 1)
- {
- Console.Write(number + " ");
- }
- else
- {
- Console.WriteLine("In this array, all the elements occurring once.");
- }
- }
- Console.Write(" --> {0} times", bigLenght);
- Console.WriteLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment