Advertisement
FLISEN

Untitled

Jan 10th, 2013
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.37 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. class MaxSequence
  5. {
  6.     static void Main(string[] args)
  7.     {
  8.  
  9.         Console.Write("Enter size of the array: ");
  10.         int n = int.Parse(Console.ReadLine());      
  11.         int[] array = new int[n];
  12.         int[] maxSequence = new int[n];
  13.         int m=0;
  14.         int max=0;
  15.         int ind = 0;
  16.  
  17.         for (int i = 0; i < n; i++)
  18.         {
  19.             array[i] = int.Parse(Console.ReadLine());
  20.         }
  21.  
  22.  
  23.         for (int j = 0; j < n-1; j++)
  24.         {
  25.             for (int k = j+1; k < n; k++)
  26.             {
  27.                 if (array[j] == array[k])
  28.                 {
  29.                     maxSequence[m]=array[j];
  30.                     m++;
  31.                 }
  32.                 else
  33.                 {
  34.                     m = 0;
  35.                     break;
  36.                 }
  37.             }
  38.         }
  39.         int p = maxSequence.Length;
  40.        
  41.         for (int l = 0; l < p; l++)
  42.         {
  43.  
  44.             if (maxSequence[p-l-1] == 0)
  45.             {
  46.                 ind++;
  47.  
  48.             }
  49.             else
  50.             {
  51.                 max = maxSequence[p-l-1];
  52.                 break;
  53.             }
  54.         }
  55.         Console.WriteLine("Max sequence is:");
  56.         for (int l = p - ind; l >= 0; l--)
  57.         {
  58.            
  59.             Console.WriteLine("{0} ", max);
  60.            
  61.         }
  62.     }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement