Advertisement
Hristo_B

Joro The Rabbit

Sep 8th, 2013
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.79 KB | None | 0 0
  1. using System;
  2.  
  3. class JoroTheRabbit
  4. {
  5.     static void Main()
  6.     {
  7.         string[] input = Console.ReadLine().Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
  8.         int[] valley = new int[input.Length];
  9.         for (int i = 0; i < input.Length; i++)
  10.         {
  11.             valley[i] = int.Parse(input[i]);
  12.         }
  13.  
  14.         int maxLength = 1;
  15.         for (int step = 1; step < valley.Length; step++)
  16.         {
  17.  
  18.             for (int startIndex = 0; startIndex < valley.Length; startIndex++)
  19.             {
  20.                 bool[] visited = new bool[valley.Length];
  21.                 visited[startIndex] = true;
  22.                 int currentLength = 1;
  23.                 int currentIndex = startIndex + step;
  24.                 int previousNumber = startIndex;
  25.  
  26.                 while (true)
  27.                 {
  28.                     if (currentIndex > valley.Length - 1)
  29.                     {
  30.                         currentIndex = currentIndex % valley.Length;
  31.                     }
  32.  
  33.                     if (currentIndex < 0)
  34.                     {
  35.                         break;
  36.                     }
  37.  
  38.                     if (!visited[currentIndex] && valley[currentIndex] > valley[previousNumber])
  39.                     {
  40.                         visited[currentIndex] = true;
  41.                         currentLength++;
  42.                         previousNumber = currentIndex;
  43.  
  44.                     }
  45.                     else
  46.                     {
  47.                         break;
  48.                     }
  49.  
  50.                     currentIndex += step;
  51.  
  52.                 }
  53.                 if (currentLength > maxLength)
  54.                 {
  55.                     maxLength = currentLength;
  56.                 }
  57.             }
  58.         }
  59.        
  60.         Console.WriteLine(maxLength);
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement