Advertisement
braveheart1989

MaxSeqOfEqualElements

Jun 5th, 2016
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.13 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _06.MaxSeqOfEqualElements
  8. {
  9.     class MaxSeqOfEqualElements
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int[] myArray = Console.ReadLine().Split().Select(int.Parse).ToArray();
  14.             int length = 1;
  15.             int maxLength = 0;
  16.             int tempNum = 0;
  17.             for (int i = 0; i < myArray.Length-1; i++)
  18.             {
  19.                 if (myArray[i] == myArray[i + 1])
  20.                 {
  21.                     length++;
  22.                 }
  23.                 else
  24.                 {
  25.                     length = 1;
  26.                 }
  27.                 if (maxLength < length)
  28.                 {
  29.                     maxLength = length;
  30.                     tempNum = myArray[i];
  31.                 }
  32.             }
  33.             for (int i = 0; i < maxLength; i++)
  34.             {
  35.                 if (maxLength >= 1)
  36.                 {
  37.                     Console.Write("{0} ",tempNum);
  38.                 }
  39.             }
  40.             Console.WriteLine();
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement