Advertisement
simonses

MaxSequenceOfEqualElements

Jan 7th, 2013
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.12 KB | None | 0 0
  1. using System;
  2.  
  3. class MaxSequenceOfEqualElements
  4. {
  5.     static void Main()
  6.     {
  7.         Console.WriteLine("Please, insert the length of the array!");
  8.         byte n = byte.Parse(Console.ReadLine());
  9.  
  10.         Console.WriteLine("Now the values:");
  11.  
  12.         //Read array
  13.         int[] array = new int[n];
  14.         for (int i = 0; i < n; i++)
  15.         {
  16.             array[i] = int.Parse(Console.ReadLine());
  17.         }
  18.  
  19.         // Compair
  20.         int count = 0;
  21.         int maxCount = 0;
  22.         int currentInt = 0;
  23.         int bigInt = 0;
  24.  
  25.         for (int i = 0; i < array.Length - 1; i++)
  26.         {
  27.             if (array[i] == array[i + 1])
  28.             {
  29.                 count++;
  30.                 currentInt = array[i];
  31.             }
  32.             else
  33.             {
  34.                 count = 0;
  35.             }
  36.             if (count >= maxCount)
  37.             {
  38.                 maxCount = count;
  39.                 bigInt = currentInt;
  40.             }
  41.         }
  42.  
  43.         // Print
  44.         for (int i = 0; i <= maxCount; i++)
  45.         {
  46.             Console.Write(bigInt);
  47.         }
  48.         Console.WriteLine();
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement