Advertisement
radidim

07.Max Sequence of Equal Elements (C# Shell App Paste)

Jan 1st, 2019
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.27 KB | None | 0 0
  1. //Disclaimer: The creator of 'C# Shell (C# Offline Compiler)' is in no way responsible for the code posted by any user.
  2. Disclaimer: The creator of 'C# Shell (C# Offline Compiler)' is in no way responsible for the code posted by any user.
  3. using System;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Collections.Generic;
  7.  
  8. namespace CSharp_Shell
  9. {
  10.  
  11.     public static class Program
  12.     {
  13.         public static void Main()
  14.         {
  15.            int[] arr = Console.ReadLine()
  16.            .Split()
  17.            .Select(int.Parse)
  18.            .ToArray();
  19.          
  20.            int count=0;
  21.            int position = 0;
  22.            int maxCount=0;
  23.            
  24.            for(int i=0; i<arr.Length-1;i++)
  25.            {
  26.                if(arr[i] == arr[i+1])
  27.                {
  28.                    count++;
  29.                    if(maxCount<count)
  30.                    {
  31.                    
  32.                    position=i-count;
  33.                    maxCount=count;
  34.                    }
  35.                    
  36.                }
  37.                else
  38.                {
  39.                    count = 0;
  40.                }
  41.            }
  42.            
  43.            for (int i = position+1; i<=position+ maxCount+1;i++)
  44.            {
  45.                Console.Write(arr[i] + " ");
  46.            }
  47.            Console.WriteLine();
  48.            
  49.         }
  50.     }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement