tanya_zheleva

07

Jan 31st, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.18 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace ExamPreparation
  5. {
  6.     class Startup
  7.     {
  8.         static void Main()
  9.         {
  10.             int[] numbers = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  11.                 .Select(int.Parse)
  12.                 .ToArray();
  13.             var currStart = 0;
  14.             var currSequence = 0;
  15.             var maxStart = 0;
  16.             var maxSequence = 0;
  17.  
  18.             for (int i = 1; i < numbers.Length; i++)
  19.             {
  20.                 if (numbers[i] - numbers[i - 1] >= 1)
  21.                 {
  22.                     currSequence++;
  23.                     currStart = i - currSequence;
  24.  
  25.                     if (currSequence > maxSequence)
  26.                     {
  27.                         maxSequence = currSequence;
  28.                         maxStart = currStart;
  29.                     }
  30.                 }
  31.                 else
  32.                 {
  33.                     currSequence = 0;
  34.                 }
  35.             }
  36.  
  37.             for (int i = maxStart; i <= maxStart + maxSequence; i++)
  38.             {
  39.                 Console.Write($"{numbers[i]} ");
  40.             }
  41.  
  42.             Console.WriteLine();
  43.         }
  44.     }
  45. }
Add Comment
Please, Sign In to add comment