stkirov

05.FollowingNumbers

Oct 25th, 2012
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.90 KB | None | 0 0
  1. using System;
  2.  
  3. namespace _05.FollowingNubers_1_
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int[] array = { 3,2,3,4,2,2,4 };            
  10.             int length = 1;
  11.             int lastElement = 0;
  12.             int bestLength = 0;
  13.  
  14.             for (int i = 0; i < array.Length-1; i++)
  15.             {
  16.                 if (array[i + 1] - array[i] == 1)
  17.                 {
  18.                     length++;
  19.                 }
  20.                 else
  21.                 {
  22.                     length = 1;
  23.                 }
  24.                 if(length > bestLength)
  25.                 {
  26.                     bestLength = length;
  27.                     lastElement = i+1;
  28.                 }
  29.             }
  30.  
  31.             for (int i = lastElement - (bestLength - 1); i <= lastElement; i++)
  32.             {
  33.                 Console.Write(array[i]);
  34.             }
  35.  
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment