Advertisement
bacco

Max Sequence of Equal Elements

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