Advertisement
martinvalchev

Max Sequence of Equal Elements LIST

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