SHARE
TWEET

01. Max Sequence of Equal Elements

a guest Feb 22nd, 2019 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp7
  8. {
  9.     class Program
  10.     {
  11.  
  12.         static void Main(string[] args)
  13.         {
  14.  
  15.             List<int> inputList = Console.ReadLine().Split().Select(int.Parse).ToList();
  16.  
  17.             int bestLength = 1;
  18.             int currentLength = 1;
  19.             int bestIndex = 0;
  20.  
  21.             for (int i = 1; i < inputList.Count; i++)
  22.             {
  23.                 if (inputList[i] == inputList[i - 1])
  24.                 {
  25.                     currentLength++;
  26.  
  27.                     if (bestLength < currentLength)
  28.                     {
  29.                         bestLength = currentLength;
  30.                         bestIndex = i;
  31.                     }
  32.                 }
  33.                 else
  34.                 {
  35.                     currentLength = 1;
  36.                 }
  37.             }
  38.  
  39.             for (int i = bestIndex; i > bestIndex - bestLength; i--)
  40.             {
  41.                 Console.Write(inputList[i] + " ");
  42.             }
  43.  
  44.  
  45.          }
  46.     }
  47. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top