Advertisement
Guest User

Untitled

a guest
May 4th, 2015
952
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.33 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace LongestIncreasSequence_5
  8. {
  9.     class LongestIncreasSequence_5
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string input = Console.ReadLine();
  14.             int[] numbers = input.Split().Select(int.Parse).ToArray();
  15.  
  16.             int counter = 1;
  17.             int maxLength = 1;
  18.             int end = 0;
  19.  
  20.             Console.Write(numbers[0]+" ");
  21.             for (int i = 1; i < numbers.Length; i++)
  22.             {
  23.                 if (numbers[i] > numbers[i - 1])
  24.                 {
  25.                     counter++;
  26.                     Console.Write(numbers[i]+" ");                  
  27.                 }
  28.                 else
  29.                 {
  30.                     counter = 1;
  31.                     Console.WriteLine();
  32.                     Console.Write(numbers[i]+" ");
  33.                 }
  34.                 if (counter > maxLength)
  35.                 {
  36.                     maxLength = counter;
  37.                     end = i;
  38.                 }
  39.             }
  40.             Console.WriteLine();
  41.             Console.Write("Longest: ");
  42.             for (int j = end - maxLength + 1; j <= end; j++)
  43.             {
  44.                 Console.Write(numbers[j]+" ");
  45.             }
  46.         }
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement