Advertisement
NelIfandieva

ArrExercises_06_MaxSeqOfEqualNums

Apr 1st, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.40 KB | None | 0 0
  1. using System;
  2. using System.Collections.Concurrent;
  3. using System.Linq;
  4.  
  5. namespace Arrays_tries_EndMarch
  6. {
  7.     class MainClass
  8.     {
  9.         public static void Main(string[] args)
  10.         {
  11.             //.Split(", ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)
  12.             char[] sep = { ' ' };
  13.             var input = Console.ReadLine();
  14.            // int num = int.Parse(Console.ReadLine());
  15.             int[] arr = input
  16.             .Split(sep, StringSplitOptions.RemoveEmptyEntries)
  17.             .Select(int.Parse)
  18.             .ToArray();
  19.  
  20.             int repeatedValue = arr[0];
  21.             var longestCount = 1;
  22.             var currentCount = 1;
  23.             for (int i = 0; i < arr.Length - 1; i++)
  24.             {
  25.                 var currentValue = arr[i];
  26.                 var nextValue = arr[i + 1];
  27.  
  28.                 if(currentValue == nextValue)
  29.                 {
  30.                     currentCount++;
  31.                     if(currentCount > longestCount)
  32.                     {
  33.                         repeatedValue = nextValue;
  34.                         longestCount = currentCount;
  35.                     }
  36.                 }
  37.                 else
  38.                 {
  39.                     currentCount = 1;
  40.                 }
  41.             }
  42.             for (int a = 1; a <= longestCount; a++)
  43.             {
  44.                 Console.Write("{0}", repeatedValue);
  45.             }
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement