Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace _05MaxAscSubArr
- {
- class MaxAscSubArr
- {
- static void Main(string[] args)
- {
- Console.Write("size of the array: ");
- int size = int.Parse(Console.ReadLine());
- int[] array = new int[size];
- int bestLen = 1;
- int bestIndex = 0;
- for (int i = 0; i < size; i++)
- {
- Console.Write("array[{0}]=", i + 1);
- array[i] = int.Parse(Console.ReadLine());
- }
- for (int i = 0; i < (array.Length - 1); i++)
- {
- int len = 1;
- int index = 0;
- int j = i;
- while ((j < array.Length-1) && array[j] < array[j+1])
- {
- index = i;
- len++;
- j++;
- }
- if (len > bestLen)
- {
- bestLen = len;
- bestIndex = index;
- }
- }
- int temp = 0;
- if (bestLen > 1)
- {
- while (temp < bestLen)
- {
- Console.Write("{0} ", array[bestIndex]);
- bestIndex++;
- temp++;
- }
- Console.WriteLine();
- }
- else
- {
- Console.WriteLine(0);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment