Advertisement
tanya_zheleva

06

Jan 31st, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.03 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace ExamPreparation
  5. {
  6.     class Startup
  7.     {
  8.         static void Main()
  9.         {
  10.             int[] numbers = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  11.                 .Select(int.Parse)
  12.                 .ToArray();
  13.             int length = 1;
  14.             int bestLength = 0;
  15.             int bestNumber = 0;
  16.  
  17.             for (int i = 0; i < numbers.Length - 1; i++)
  18.             {
  19.                 if (numbers[i] == numbers[i+1])
  20.                 {
  21.                     length++;
  22.                 }
  23.                 else
  24.                 {
  25.                     length = 1;
  26.                 }
  27.  
  28.                 if (length > bestLength)
  29.                 {
  30.                     bestLength = length;
  31.                     bestNumber = numbers[i];
  32.                 }
  33.             }
  34.  
  35.             for (int i = 0; i < bestLength; i++)
  36.             {
  37.                 Console.Write($"{bestNumber} ");
  38.             }
  39.  
  40.             Console.WriteLine();
  41.         }
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement