fork download
  1. import java.io.BufferedReader;
  2. import java.io.File;
  3. import java.io.FileNotFoundException;
  4. import java.io.FileReader;
  5. import java.io.IOException;
  6. import java.io.InputStreamReader;
  7.  
  8. public class Main {
  9. public static void main(String[] args) throws FileNotFoundException, IOException {
  10. try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))) {
  11. String line;
  12. next: while ((line = reader.readLine()) != null) {
  13. String[] split = line.split(" ");
  14. int num_elements = Integer.parseInt(split[0]);
  15. int i;
  16. boolean[] array = new boolean[num_elements - 1];
  17. for (i = 1; i <= num_elements; i++) {
  18. int num = Integer.parseInt(split[i]);
  19. if (i + 1 <= num_elements) {
  20. int num2 = Integer.parseInt(split[i + 1]);
  21. double abs = Math.abs(num - num2);
  22. if (abs - 1 < num_elements - 1) {
  23. array[(int) (abs - 1)] = true;
  24. }
  25. }
  26. System.out.printf("%d ", num);
  27. }
  28. for (int j = 0; j < array.length; j++)
  29. if (!array[j]) {
  30. System.out.printf("\tNot Jolly\n");
  31. continue next;
  32. }
  33. System.out.printf("\tJolly\n");
  34. }
  35. }
  36. }
  37. }
Success #stdin #stdout 0.05s 4386816KB
stdin
4 1 4 2 3
8 1 6 -1 8 9 5 2 7
5 1 4 2 -1 6
4 19 22 24 21
4 19 22 24 25
4 2 -1 0 2
stdout
1 4 2 3 	Jolly
1 6 -1 8 9 5 2 7 	Not Jolly
1 4 2 -1 6 	Not Jolly
19 22 24 21 	Not Jolly
19 22 24 25 	Jolly
2 -1 0 2 	Jolly