题目链接:https://www.luogu.com.cn/problem/P1152
代码如下:
import java.util.Arrays;
import java.util.Scanner;
public class P1152 {
/**
*@title: main
*@description: TODO
*@author: 梁树鹏
*@date: 2021年11月28日 下午2:16:53
*@param args
*@throws:
*/
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int num = scanner.nextInt();
int array[] = new int[num];
for(int i = 0;i<num;i++) {
array[i] = scanner.nextInt();
}
int result[] = new int[num-1];
// 遍历数组
for(int i = 0;i<array.length-1;i++) {
result[i] = Math.abs(array[i]-array[i+1]);
}
// 排序
Arrays.sort(result);
int count = 0;
// 判断是否满足条件
for(int j = 0;j<num-1;j++) {
if(result[j] == j+1) {
count++;
continue;
}else {
System.out.println("Not jolly");
break;
}
}
if(count == num-1) {
System.out.println("Jolly");
}
}
}