Advertisement
GogoK

LongestSequence

May 6th, 2015
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.39 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. internal class LongestSequence
  6. {
  7.     private static void Main()
  8.     {
  9.         Console.Write("Entere Numbers:  ");
  10.         string input = Console.ReadLine();
  11.         int[] numbers = input.Split(' ').Select(int.Parse).ToArray();
  12.         List<int> biggest = new List<int>();
  13.         List<int> current = new List<int>();
  14.  
  15.         current.Add(numbers[0]);
  16.         for (int i = 1; i < numbers.Length; i++)
  17.         {
  18.             bool isBigger = CompareValues(numbers[i-1], numbers[i]);
  19.             if (isBigger)
  20.             {
  21.                 current.Add(numbers[i]);
  22.             }
  23.             if (current.Count > biggest.Count)
  24.             {
  25.                 biggest = current.ToList();
  26.             }
  27.             if(!isBigger)
  28.             {
  29.                 PrintingValues(current);
  30.                 current.Clear();    
  31.                 current.Add(numbers[i]);
  32.             }
  33.         }
  34.         PrintingValues(current);
  35.         Console.Write("Longest: ");
  36.         PrintingValues(biggest);
  37.     }
  38.  
  39.     static void PrintingValues(List<int> thisList)
  40.     {
  41.         thisList.ForEach(x => Console.Write(x + " "));
  42.         Console.WriteLine();
  43.     }
  44.  
  45.     static bool CompareValues(int a, int b)
  46.     {
  47.         bool check = false;
  48.         if (a < b)
  49.         {
  50.             check = true;
  51.         }
  52.         return check;
  53.     }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement