当前位置:网站首页>刷题-洛谷-P1152 欢乐的跳
刷题-洛谷-P1152 欢乐的跳
2022-07-25 13:32:00 【宋向上_UP】
P1152 欢乐的跳-C语言
1、题目

2、解题过程
结果:
代码:
//洛谷 P1152 欢乐的跳
#include <stdio.h>
#define NUM 1000//1≤n≤1000
int main() {
int n;//n个元素
int a[NUM];//n个元素的整数数组
int d_value[NUM] = {
0 };
int j = 0;
int i;
int temp;
scanf("%d", &n);
for (i = 0; i < n; i++) {
if (i == 0) {
scanf("%d", &a[i]);
}
else {
scanf("%d", &a[i]);
temp= a[i] - a[i - 1];
d_value[j] = temp > 0 ? temp : (-1 * temp);//绝对值
j++;
}
}
/* printf("差值数组的数据为:\n"); for (i = 0; i < n-1; i++) {//之后n-1个差值数 printf(" %d ", d_value[i]); }*/
int k = n - 1;
//利用冒泡排序判断是否有重复的值,并判断两端的端点
for (i = 0; i < k-1 ; i++) {
//进行k-1次冒泡
for (j = 1; j <k; j++) {
if (d_value[j] == d_value[j - 1]) {
printf("Not jolly");//不符合欢乐的跳
return 0;
}
else if (d_value[j - 1] > d_value[j]) {
temp = d_value[j-1];
d_value[j-1] = d_value[j];
d_value[j] = temp;
}
}
}
/* printf("\n排序后的差值数组的数据为:\n"); for (i = 0; i < n-1; i++) { printf(" %d ", d_value[i]); } printf("\n");*/
if (d_value[0] != 1) {
printf("Not jolly");//不符合欢乐的跳
}
else if(d_value[n - 2] != (n - 1)){
printf("Not jolly");//不符合欢乐的跳
}
else {
printf("Jolly");//符合欢乐的跳
}
/* if ((d_value[0] == 1) & (d_value[n - 2] == n - 1)) { printf("Jolly");//符合欢乐的跳 } else { printf("Not jolly");//不符合欢乐的跳 }*/
return 0;
}
边栏推荐
- Online Learning and Pricing with Reusable Resources: Linear Bandits with Sub-Exponential Rewards: Li
- How to realize the configuration method of user password free login?
- hcip第七天笔记
- 0710RHCSA
- 【CTR】《Towards Universal Sequence Representation Learning for Recommender Systems》 (KDD‘22)
- stable_ Baselines quick start
- 备战2022 CSP-J1 2022 CSP-S1 初赛 视频集
- 0713RHCSA
- ThreadLocal&Fork/Join
- Gym安装、调用以及注册
猜你喜欢

6W+字记录实验全过程 | 探索Alluxio经济化数据存储策略

ESP32-C3 基于Arduino框架下Blinker点灯控制10路开关或继电器组

QGIS loading online map: Gaode, Tiandi map, etc

0716RHCSA

ES6 array de duplication new set()
详解浮点数的精度问题

2022年下半年软考初级程序员备考

并发编程 — 内存模型 JMM
![Detailed explanation of the training and prediction process of deep learning [taking lenet model and cifar10 data set as examples]](/img/70/2b5130be16d7699ef7db58d9065253.png)
Detailed explanation of the training and prediction process of deep learning [taking lenet model and cifar10 data set as examples]

基于百问网IMX6ULL_PRO开发板移植LCD多点触摸驱动(GT911)
随机推荐
嵌入式代码如何进行重构?
Simple understanding of flow
uniapp处理后台传输图片
QGIS加载在线地图:高德、天地图等
The migration of arm architecture to alsa lib and alsa utils is smooth
Convolutional neural network model -- lenet network structure and code implementation
Blindly expanding the scale of the meta universe has deviated from the development logic of the meta universe
好友让我看这段代码
How to solve the problem of taking up too much space when recording and editing videos?
央行数研所穆长春:数字人民币可控匿名是维护公众利益和金融安全的客观需要
Convolutional neural network model -- googlenet network structure and code implementation
VIM basic operation summary
并发编程之AQS
【GCN-CTR】DC-GNN: Decoupled GNN for Improving and Accelerating Large-Scale E-commerce Retrieval WWW22
【视频】马尔可夫链原理可视化解释与R语言区制转换MRS实例|数据分享
stable_ Baselines quick start
Uniapp handles background transfer pictures
VIM tip: always show line numbers
G027-OP-INS-RHEL-04 RedHat OpenStack 创建自定义的QCOW2格式镜像
QingChuang technology joined dragon lizard community to build a new ecosystem of intelligent operation and maintenance platform