TodorMitev

MaxAscSubArr

Dec 5th, 2011
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.52 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace _05MaxAscSubArr
  7. {
  8.     class MaxAscSubArr
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             Console.Write("size of the array: ");
  13.             int size = int.Parse(Console.ReadLine());
  14.             int[] array = new int[size];
  15.             int bestLen = 1;
  16.             int bestIndex = 0;
  17.             for (int i = 0; i < size; i++)
  18.             {
  19.                 Console.Write("array[{0}]=", i + 1);
  20.                 array[i] = int.Parse(Console.ReadLine());
  21.             }
  22.             for (int i = 0; i < (array.Length - 1); i++)
  23.             {
  24.                 int len = 1;
  25.                 int index = 0;
  26.                 int j = i;
  27.                 while ((j < array.Length-1) && array[j] < array[j+1])
  28.                 {
  29.                     index = i;
  30.                     len++;
  31.                     j++;
  32.                 }
  33.                 if (len > bestLen)
  34.                 {
  35.                     bestLen = len;
  36.                     bestIndex = index;
  37.                 }
  38.             }
  39.             int temp = 0;
  40.             if (bestLen > 1)
  41.             {
  42.                 while (temp < bestLen)
  43.                 {
  44.                     Console.Write("{0} ", array[bestIndex]);
  45.                     bestIndex++;
  46.                     temp++;
  47.                 }
  48.                 Console.WriteLine();
  49.             }
  50.             else
  51.             {
  52.                 Console.WriteLine(0);
  53.             }
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment