VelizarAvramov

06. Max Sequence of Equal Elements

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