Advertisement
obedmarsh

01. Max Sequence of Equal Elements

Jun 17th, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.27 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 SoftUni
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             List<int> nums = new List<int>();
  14.             nums = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
  15.             int pos = 0;
  16.             int count = 1;
  17.             int bestPos = 0;
  18.             int bestCount = 1;
  19.             do
  20.             {
  21.                 if (nums.Count == 1)
  22.                 {
  23.                     break;
  24.                 }
  25.                 if (nums[pos] != nums[pos + 1])
  26.                 {
  27.                     count = 1;
  28.                     pos++;
  29.                 }
  30.                 else if (nums[pos] == nums[pos + 1])
  31.                 {
  32.                     count++;
  33.                     pos++;
  34.                 }
  35.                 if (bestCount < count)
  36.                 {
  37.                     bestCount = count;
  38.                     bestPos = pos + 1 - bestCount;
  39.                 }
  40.             }
  41.             while (pos + 1 < nums.Count);
  42.             for (int i = bestPos; i < (bestPos + bestCount); i++)
  43.             {
  44.                 Console.Write(nums[i] + " ");
  45.             }
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement