MiroslavKisov

MaxSequenceOfEqualElements

Oct 8th, 2017
687
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.16 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _06.MaxSequenceOfEqualElements
  5. {
  6.     public class StartUp
  7.     {
  8.         public static void Main()
  9.         {
  10.             long[] numbers = Console.ReadLine()
  11.                 .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  12.                 .Select(long.Parse)
  13.                 .ToArray();
  14.             int start = 0;
  15.             int bestStart = 0;
  16.             int length = 0;
  17.             int bestLength = 0;
  18.             for (int i = 1; i < numbers.Length; i++)
  19.             {
  20.                 if (numbers[start] == numbers[i])
  21.                 {
  22.                     length++;
  23.                     if (length > bestLength)
  24.                     {
  25.                         bestLength = length;
  26.                         bestStart = start;
  27.                     }
  28.                 }
  29.                 else
  30.                 {
  31.                     start++;
  32.                     i = start;
  33.                     length = 0;
  34.                 }
  35.             }
  36.             for (int i = 0; i <= bestLength; i++)
  37.             {
  38.                 Console.Write(numbers[bestStart + i] + " ");
  39.             }
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment