Advertisement
bacco

Max Sequence of Equal Elements

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