Advertisement
bacco

Max Sequence of Equal Elements

May 6th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.06 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace test
  5. {
  6.     class MainClass
  7.     {
  8.         public static void Main()
  9.         {
  10.             int[] arrFirst = Console.ReadLine()
  11.                                       .Split(' ')
  12.                                         .Select(int.Parse)
  13.                                           .ToArray();
  14.  
  15.             var maxNum = 0;
  16.             var counter = 1;
  17.             var maxCounter = 0;
  18.  
  19.             for (int i = 0; i < arrFirst.Length - 1; i++)
  20.             {
  21.                 if (arrFirst[i] == arrFirst[i + 1])
  22.                 {
  23.                     counter++;
  24.                     if (maxCounter < counter)
  25.                     {
  26.                         maxCounter = counter;
  27.                         maxNum = arrFirst[i];
  28.                     }
  29.                 }
  30.                 else
  31.                 {
  32.                     counter = 1;
  33.                 }
  34.             }
  35.  
  36.             for (int i = 0; i < maxCounter; i++)
  37.             {
  38.                 Console.Write(maxNum + " ");
  39.             }
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement