Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.ByteArrayInputStream;
- import java.util.Scanner;
- public class JoroTheRabbit {
- static void fakeInput() {
- String test = "1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0";
- System.setIn(new ByteArrayInputStream(test.getBytes()));
- }
- public static void main(String[] args) {
- //fakeInput();
- Scanner scanner = new Scanner(System.in);
- String[] array = scanner.nextLine().split(", ");
- int[] numbers = new int[array.length];
- for (int i = 0; i < numbers.length; i++) {
- numbers[i] = Integer.parseInt(array[i]);
- }
- int currentLength = 1;
- int maxLength = 0;
- int index = 0;
- int nextPosition = 0;
- for (int startIndex = 0; startIndex < numbers.length; startIndex++) {
- for (int step = 1; step < numbers.length; step++) {
- index = startIndex;
- currentLength = 1;
- nextPosition = (index + step) % numbers.length;
- while (nextPosition != startIndex && numbers[nextPosition] > numbers[index]) {
- currentLength++;
- index = nextPosition;
- nextPosition = (index + step) % numbers.length;
- }
- if(currentLength > maxLength){
- maxLength = currentLength;
- }
- }
- }
- System.out.println(maxLength);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment