Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Write a program to find all increasing sequences inside an array of integers.
- //The integers are given on a single line, separated by a space.
- //Print the sequences in the order of their appearance in the input array, each at a single line.
- //Separate the sequence elements by a space. Find also the longest increasing sequence and print it at the last line.
- //If several sequences have the same longest length, print the left-most of them.
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Runtime.InteropServices;
- namespace Problem_5.Longest_Increasing_Sequence
- {
- class LongestIncSeq
- {
- static void Main()
- {
- var input = Console.ReadLine().Split(' ').ToArray();
- int[] numbers = Array.ConvertAll(input, element => Convert.ToInt32(element));
- List<int> sequences = new List<int>();
- List<List<int>> inceptionList = new List<List<int>>();
- int tmpNumber = numbers[0];
- //2 3 4 1 50 2 3 4 5
- for (int j = 1; j < numbers.Length; j++)
- {
- if (numbers[j] == numbers.Last())
- {
- //Console.Write(string.Join(" ", sequences.Distinct().ToList()));
- //Console.Write(" " + numbers.Last());
- inceptionList.Add(sequences);
- //Console.WriteLine();
- sequences.Clear();
- }
- else if (tmpNumber < numbers[j])
- {
- sequences.Add(tmpNumber);
- sequences.Add(numbers[j]);
- tmpNumber = numbers[j];
- }
- else if (tmpNumber > numbers[j])
- {
- //Console.Write(string.Join(" ", sequences.Distinct().ToList()));
- //Console.WriteLine();
- inceptionList.Add(sequences);
- sequences.Clear();
- tmpNumber = numbers[j];
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement