| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
哪位帮我看看代码啊,我觉得没问题,可就是 WA#include<iostream>
#include<math.h>
#define N 3000
using namespace std;
int main()
{
int n,i,j;
int a[N],index[N];
while(cin>>n)
{
if(n==1)
{
cout<<"Jolly"<<endl;
continue;
}
else
{
i=0;
while(i<n)
{
cin>>a[i];
index[i]=0;
++i;
}
i=0;
while(i<n-1)
{
j=abs(a[i]-a[i+1]);
if(j>=n||index[j]==1)
{
cout<<"Not jolly"<<endl;
break;
}
index[j]=1;
++i;
}
if(i==n-1)cout<<"Jolly"<<endl;
}
}
return 0;
}
我的想法很简单,用一个指标数组来指示1到n-1的数哪些已经用过了,如果重复出现,则不是;如果能执行到最后,则是
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator