Advertisement
martinvalchev

Max_Sequence_of_Equal_Elements

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