Advertisement
Guest User

Untitled

a guest
May 6th, 2015
382
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.05 KB | None | 0 0
  1. //Write a program to find all increasing sequences inside an array of integers.
  2. //The integers are given on a single line, separated by a space.
  3. //Print the sequences in the order of their appearance in the input array, each at a single line.
  4. //Separate the sequence elements by a space. Find also the longest increasing sequence and print it at the last line.
  5. //If several sequences have the same longest length, print the left-most of them.
  6.  
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Linq;
  10. using System.Runtime.InteropServices;
  11.  
  12. namespace Problem_5.Longest_Increasing_Sequence
  13. {
  14.     class LongestIncSeq
  15.     {
  16.         static void Main()
  17.         {
  18.             var input = Console.ReadLine().Split(' ').ToArray();
  19.             int[] numbers = Array.ConvertAll(input, element => Convert.ToInt32(element));
  20.             List<int> sequences = new List<int>();
  21.             List<List<int>> inceptionList = new List<List<int>>();
  22.             int tmpNumber = numbers[0];
  23.  
  24.             //2 3 4 1 50 2 3 4 5
  25.             for (int j = 1; j < numbers.Length; j++)
  26.             {
  27.                 if (numbers[j] == numbers.Last())
  28.                 {
  29.                     //Console.Write(string.Join(" ", sequences.Distinct().ToList()));
  30.                     //Console.Write(" " + numbers.Last());
  31.                     inceptionList.Add(sequences);
  32.                     //Console.WriteLine();
  33.                     sequences.Clear();
  34.                 }
  35.                 else if (tmpNumber < numbers[j])
  36.                 {
  37.                     sequences.Add(tmpNumber);
  38.                     sequences.Add(numbers[j]);
  39.                     tmpNumber = numbers[j];
  40.                 }
  41.                 else if (tmpNumber > numbers[j])
  42.                 {
  43.                     //Console.Write(string.Join(" ", sequences.Distinct().ToList()));
  44.                     //Console.WriteLine();
  45.                     inceptionList.Add(sequences);
  46.                     sequences.Clear();
  47.                     tmpNumber = numbers[j];
  48.                 }
  49.             }
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement