Advertisement
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;
- using System.Threading.Tasks;
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Please enter an integer for the length of the array: ");
- int n = int.Parse(Console.ReadLine());
- int[] array = new int[n];
- List<int> sequence = new List<int>();
- List<int> sequenceA = new List<int>();
- Console.WriteLine("Please enter integers to fill in the array: ");
- for (int i = 0; i < array.Length; i++)
- {
- array[i] = int.Parse(Console.ReadLine());
- }
- for (int i = 0; i < array.Length - 1; i++)
- {
- if(array[i]<array[i+1])
- {
- sequence.Add(array[i]);
- if((i<=array.Length-3&&array[i+2]<=array[i+1])||(i==array.Length-2&&array[i]<array[i+1]))
- {
- sequence.Add(array[i + 1]);
- }
- }
- if(sequenceA.Count<sequence.Count)
- {
- sequenceA = sequence.ToList();
- }
- else if (array[i]>=array[i+1])
- {
- sequence.Clear();
- }
- }
- Console.WriteLine("The longest increasing sequence is: ");
- foreach(int member in sequenceA)
- {
- Console.WriteLine(member+" ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement