Advertisement
radidim

MaxSequenceOfEqualElements.no (C# Shell App Paste)

Oct 6th, 2019
164
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.17 KB | None | 0 0
  1. //Disclaimer: The creator of 'C# Shell (C# Offline Compiler)' is in no way responsible for the code posted by any user.
  2. using System;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Collections.Generic;
  6.  
  7. namespace Program
  8. {
  9.  
  10.     public class MaxSequenceOfEqualElements
  11.     {
  12.         public static void Main()
  13.         {
  14.             //2 1 1 2 3 3 2 2 2 1
  15.            
  16.             int[] a=Console.ReadLine().Split().Select(int.Parse).ToArray();
  17.             int count=0;
  18.             int num=0;
  19.             int num1=0;
  20.             int count1=0;
  21.             int start=0;
  22.            
  23.             for(int i=0;i<a.Length-1;i++)
  24.             {
  25.                 if(a[i]==a[i+1])
  26.                 {
  27.                     num=a[i];
  28.                     count++;
  29.                 }
  30.                 else if(a[i]!=a[i+1])
  31.                 {
  32.                     start=a[i+1];
  33.                 }
  34.            
  35.             for(int j =start;j<a.Length-1;j++)
  36.             {
  37.                 if(a[j]==a[j+1])
  38.                 {
  39.                     num1=a[j];
  40.                     count1++;
  41.                 }
  42.                 if(count1>count)
  43.                 {
  44.                     num1=num;
  45.                     count1=count;
  46.                     break;
  47.                 }
  48.            
  49.             }
  50.             }
  51.             for(int i=0;i<count;i++)
  52.                 {
  53.                     Console.Write(num+" ");
  54.                 }
  55.            
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement