洛谷-P1152 欢乐的跳

 

 

 

 代码如下(c++):

#include <iostream>
#include <algorithm>    //内含sort()函数
#include <cmath>    //内含abs()函数
using namespace std;

int main(){
	int n;
	cin >> n;
	int num[n],div[n-1];
	for(int i = 0; i < n; ++i){
		cin >> num[i];
	}
	for(int i = 0; i < n-1; ++i){
		div[i] = abs(num[i] - num[i+1]);
	}
	sort(div,div+n-1);
	for(int i = 0; i < n - 1; ++i){
		if(div[i] != (i+1)){
			cout << "Not jolly";
			return 0;
		}
	}
	cout << "Jolly";
	return 0;
}

运行结果如下:

 

posted @ 2022-04-02 21:42  月光煎茶  阅读(201)  评论(0编辑  收藏  举报