题目
解题思路
1. 模拟题
2. 用hash判断diff(1~n-1)
3. 注意diff可能超过n-1,所以要避免对hash表的越界访问
4. 每行都要输出一个换行符
通过代码
#include<stdio.h>
#include<string.h>
#define N 3000
bool diff[N];
int num[N];
int main(){
#ifdef DEBUG
freopen("in","r",stdin);
freopen("out","w",stdout);
#endif
int n;
int tmp;
bool jolly;
while(scanf("%d",&n)!=EOF){
//init
jolly=true;
memset(diff,0,sizeof(diff));
//input
scanf("%d",&num[0]);
for(int i=1;i<n;++i){
scanf("%d",&num[i]);
tmp=num[i]-num[i-1];
if(tmp<0)
tmp=tmp*(-1);
if(tmp<=n-1)
diff[tmp]=true;
}
//check
for(int i=1;i<n;++i)
if(!diff[i]){
jolly=false;
break;
}
//print results
if(jolly)
printf("Jolly\n");
else
printf("Not jolly\n");
}
return 0;
}