Mishakis

JoroTheRabbit

Dec 2nd, 2018
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.45 KB | None | 0 0
  1. import java.io.ByteArrayInputStream;
  2. import java.util.Scanner;
  3.  
  4. public class JoroTheRabbit {
  5.     static void fakeInput() {
  6.         String test = "1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0";
  7.         System.setIn(new ByteArrayInputStream(test.getBytes()));
  8.     }
  9.  
  10.     public static void main(String[] args) {
  11.         //fakeInput();
  12.         Scanner scanner = new Scanner(System.in);
  13.  
  14.         String[] array = scanner.nextLine().split(", ");
  15.         int[] numbers = new int[array.length];
  16.  
  17.         for (int i = 0; i < numbers.length; i++) {
  18.             numbers[i] = Integer.parseInt(array[i]);
  19.         }
  20.  
  21.         int currentLength = 1;
  22.         int maxLength = 0;
  23.         int index = 0;
  24.  
  25.         int nextPosition = 0;
  26.  
  27.  
  28.         for (int startIndex = 0; startIndex < numbers.length; startIndex++) {
  29.             for (int step = 1; step < numbers.length; step++) {
  30.  
  31.                 index = startIndex;
  32.                 currentLength = 1;
  33.                 nextPosition = (index + step) % numbers.length;
  34.  
  35.  
  36.                 while (nextPosition != startIndex && numbers[nextPosition] > numbers[index]) {
  37.                     currentLength++;
  38.                     index = nextPosition;
  39.                     nextPosition = (index + step) % numbers.length;
  40.                 }
  41.  
  42.                 if(currentLength > maxLength){
  43.                     maxLength = currentLength;
  44.                 }
  45.             }
  46.  
  47.         }
  48.         System.out.println(maxLength);
  49.     }
  50.  
  51. }
Advertisement
Add Comment
Please, Sign In to add comment