Advertisement
YavorGrancharov

Max_Sequence_of_Equal_Elements

Oct 13th, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.74 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. public class Max_Sequence_of_Equal_Elements
  6. {
  7.     public static void Main()
  8.     {
  9.         int[]arr = Console.ReadLine()
  10.         .Split().Select(int.Parse).ToArray();
  11.         int maxSeqSize = 1;
  12.         int tempSeqSize = 1;
  13.         int output = 0;
  14.         for(int i = 0; i < arr.Length - 1;i++)
  15.         {
  16.             if (arr[i] == arr[i + 1])
  17.             {
  18.                 tempSeqSize++;
  19.                 if (tempSeqSize > maxSeqSize)
  20.                 {
  21.                     maxSeqSize = tempSeqSize;
  22.                     output = arr[i];
  23.                 }
  24.             }
  25.             else
  26.             {
  27.                 tempSeqSize = 1;
  28.             }
  29.          
  30.             if(maxSeqSize == 1)
  31.             {
  32.                 output = arr[0];
  33.             }
  34.         }
  35.         for(int i = 0; i < maxSeqSize; i++)
  36.         {
  37.             Console.Write(output + " ");
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement