WindFell

Max Equal Sequence

Apr 5th, 2018
258
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.23 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class MaxSequenceOfEqualElements
  6. {
  7.     static void Main(string[] args)
  8.     {
  9.         List<int> numbers = Console.ReadLine()
  10.             .Split(' ')
  11.             .Select(int.Parse)
  12.             .ToList();
  13.         string result = "";
  14.         int sequenceLength = 0;
  15.  
  16.         for (int index = 0; index < numbers.Count - 1; index++)
  17.         {
  18.             int count = 0;
  19.             List<int> temp = new List<int>();
  20.             temp.Add(numbers[index]);
  21.  
  22.             for (int next = index + 1; next < numbers.Count; next++)
  23.             {
  24.                 if (numbers[index] == numbers[next])
  25.                 {
  26.                     count++;
  27.                     temp.Add(numbers[index]);
  28.                 }
  29.                 else
  30.                 {
  31.                     break;
  32.                 }
  33.             }
  34.  
  35.             if (count > sequenceLength)
  36.             {
  37.                 sequenceLength = count;
  38.                 result = string.Join(" ", temp);
  39.             }
  40.         }
  41.  
  42.         if (numbers.Count == 1 || sequenceLength == 0)
  43.         {
  44.             result = numbers[0].ToString();
  45.            
  46.         }
  47.  
  48.         Console.WriteLine(result);
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment