Advertisement
Guest User

solution

a guest
Aug 5th, 2016
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.32 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 _1.MaxSequenceOfEqualElements
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             List<int> numbers = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
  14.             var len = 1;
  15.             var maxLen = 1;
  16.  
  17.             var maxNumbers = 0;
  18.             for (int position = 0; position < numbers.Count - 1; position++)
  19.             {
  20.                 if (numbers[position] == numbers[position + 1])
  21.                 {
  22.                     len++;
  23.                     if (len > maxLen)
  24.                     {
  25.  
  26.                         maxLen = len;
  27.                         maxNumbers = numbers[position];
  28.                     }
  29.                 }
  30.  
  31.                 else
  32.                 {
  33.                     len = 1;
  34.  
  35.  
  36.                 }
  37.  
  38.  
  39.             }
  40.             if (maxLen == 1)
  41.             {
  42.                 maxNumbers = numbers[0];
  43.                 Console.WriteLine(maxNumbers);
  44.  
  45.             }
  46.             else
  47.             {
  48.                 for (int i = 0; i < maxLen; i++)
  49.                 {
  50.                     Console.Write(maxNumbers + " ");
  51.                 }
  52.                 Console.WriteLine();
  53.             }
  54.  
  55.  
  56.  
  57.  
  58.         }
  59.     }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement