5 回答
TA贡献1条经验 获得超1个赞
#include<cmath>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<stack>
using namespace std;
const int maxn=3110;
int main()
{
int n,a[maxn],b[maxn];
cin>>n;
if(n==1)
{
cout<<"Jolly";
return 0;
}
int tot=0;
memset(a,0,sizeof(a));memset(b,0,sizeof(b));
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
for(int i=1;i<n;i++)
{
b[i]=fabs(a[i]-a[i+1]);
tot++;
}
sort(b,b+tot+1,less<int>());
for(int i=1;i<n-1;i++)
{
if(b[i]+1!=b[i+1])
{
cout<<"Not jolly";
return 0;
}
}
if(b[n-2]+1!=b[n-1])cout<<"Not jolly";
cout<<"Jolly";
return 0;
}
TA贡献5条经验 获得超3个赞
#include<cstdio>#include<algorithm>using namespace std;int abs(int n){if(n>=0)return n;else return -n;}int main(){int n,i,a[110000],b[100001],m=0,p=1;scanf("%d",&n);if(n==1){printf("Jolly");return 0;}for(i=1;i<=n;i++)scanf("%d",&a[i]);for(i=1;i<n;i++)b[++m]=abs(a[i+1]-a[i]);sort(b+1,b+m+1);for(i=1;i<=m;i++)if(b[i]!=p++){printf("Not jolly");return 0;}printf("Jolly");return 0;}
TA贡献2条经验 获得超1个赞
#include<cstdio>#include<algorithm>using namespace std;int abs(int n){if(n>=0)return n;else return -n;}int main(){int n,i,a[110000],b[100001],m=0,p=1;scanf("%d",&n);if(n==1){printf("Jolly");return 0;}for(i=1;i<=n;i++)scanf("%d",&a[i]);for(i=1;i<n;i++)b[++m]=abs(a[i+1]-a[i]);sort(b+1,b+m+1);for(i=1;i<=m;i++)if(b[i]!=p++){printf("Not jolly");return 0;}printf("Jolly");return 0;}
- 5 回答
- 0 关注
- 8191 浏览
添加回答
举报