Advertisement
xellscream

EqualElementsOfSequence

Jan 9th, 2013
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.17 KB | None | 0 0
  1. using System;
  2.  
  3. class EqualElementsOfSequence
  4. {
  5.     static void Main()
  6.     {
  7.         int a, b, count, maxCount, current;
  8.  
  9.         Console.Write("Enter size of the array: ");
  10.         int num = int.Parse(Console.ReadLine());
  11.         int[] arr = new int[num];
  12.  
  13.         count = 1;
  14.         maxCount = 0;
  15.  
  16.         for (int indexOne = 0, indexTwo = 1; indexTwo < num; indexOne += 2, indexTwo += 2)
  17.         {
  18.             a = arr[indexOne];
  19.             b = arr[indexTwo];
  20.             if (a == b)
  21.             {
  22.                 count++;
  23.                 if (count > maxCount)
  24.                 {
  25.                     maxCount = count;
  26.                     current = arr[indexOne];
  27.                 }
  28.                 else
  29.                 {
  30.                     continue;
  31.                 }
  32.             }
  33.             else
  34.             {
  35.                 count = 1;
  36.             }
  37.         }
  38.         int printed = current;
  39.        
  40.         Console.Write("The biggest sequence is { ");
  41.         for(int index = 0; index < maxCount;index++)
  42.         {
  43.             Console.Write("{0} ",current);
  44.         }
  45.         Console.WriteLine("}    with {0} elements.", maxCount);
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement