Advertisement
Radost09

P07_Max_Sequence_of_Equal_Elements

Feb 11th, 2019
185
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.02 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace P07_Max_Sequence_of_Equal_Elements
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int[] number = Console.ReadLine()
  11.                 .Split(' ')
  12.                 .Select(int.Parse)
  13.                 .ToArray();
  14.             int start = 0;
  15.             int count = 0;
  16.             int max = 0;
  17.  
  18.             for (int i = 0; i < number.Length-1; i++)
  19.             {
  20.                 if(number[i] == number[i+1])
  21.                 {
  22.                     count++;
  23.                     if(count > max)
  24.                     {
  25.                         start = i - count;
  26.                         max = count;
  27.                     }
  28.                 }
  29.                 else
  30.                 {
  31.                     count = 0;
  32.                 }
  33.             }
  34.             for (int i = start + 1; i <= start + max + 1; i++)
  35.             {
  36.                 Console.Write(number[i] + " ");
  37.             }
  38.             Console.WriteLine();
  39.         }
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement