先排序,然后看第一个和最后一个元素是否为1和n-1
#include<stdio.h>
#include<stdlib.h>
void sort(int * num, int n)
{
int temp;
for (int i = 0; i < n-1; i++) {
for (int j = i+1; j < n; j++) {
if (num[i] > num[j]) {
temp = num[i];
num[i] = num[j];
num[j] = temp;
}
}
}
}
int main(void)
{
int num[3500], n, count, temp[3500], i, flag;
while (scanf("%d", &n) != EOF) {
flag = count = 0;
for (int i = 0; i < n; i++) {
scanf("%d", &num[i]);
}
for (i = 0; i < n-1; i++) {
temp[i] = abs(num[i] - num[i+1]);
count++;
}
sort(temp, count);
for (int j = 1; j < n; j++) {
if (temp[j- 1] != j) {
flag = 1;
break;
}
}
printf("%s\n", flag?"Not jolly":"Jolly");
}
return 0;
}