Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Diagnostics.CodeAnalysis;
- using System.Linq;
- using System.Numerics;
- namespace SoftuniExercisesWithVariables
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Enter your array here(add any number not connected to your array at the end.): ");
- int[] array = Console.ReadLine().Split(" ").Select(int.Parse).ToArray();
- int longestEqual = 0;
- int currentLongest = 1;
- int startIndex = 0;
- int lastIndex = 0;
- for (int i = 0; i < array.Length - 1; i++)
- {
- if(array[i] == array[i + 1])
- {
- currentLongest++;
- }
- else
- {
- if(currentLongest > longestEqual)
- {
- longestEqual = currentLongest;
- lastIndex = i;
- }
- currentLongest = 1;
- }
- }
- startIndex = lastIndex - longestEqual + 1;
- for(int k = startIndex; k <= lastIndex; k++)
- {
- Console.Write(array[k] + " ");
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment