ZCMU--1857: Problem C: Jolly Jumpers

ZCMU--1857: Problem C: Jolly Jumpers,第1张

题目描述

A sequence of n > 0 integers is called a jolly jumper if the absolute values of the difference between successive elements take on all the values 1 through n-1. For instance,

1 4 2 3

is a jolly jumper, because the absolutes differences are 3, 2, and 1 respectively. The definition implies that any sequence of a single integer is a jolly jumper. You are to write a program to determine whether or not each of a number of sequences is a jolly jumper.

Each line of input contains an integer n < 3000 followed by n integers representing the sequence. For each line of input, generate a line of output saying "Jolly" or "Not jolly".

样例输入

4  1  4  2  3

5 1 4 2 -1 6

样例输出

Jolly

Not jolly

解析:题目就是问输入的N个数,两两相邻的差值,最后是否1到N-1每个数都有


所以我们可以直接利用数组来解决。


#include 
#include 
int k[3000];//存储输入的数 
int h[10005];//存储差值,差值为2就存入k【2】,如此 
int main()
{
	int n,i,shi;
	while(~scanf("%d",&n)){
		for(i=0;i<10005;i++) h[i]=0; //清空一下 
		for(i=0;i

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/564719.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-04-06
下一篇 2022-04-06

发表评论

登录后才能评论

评论列表(0条)