当前位置:网站首页>刷题-洛谷-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;
}
边栏推荐
- hcip第八天实验
- uniapp处理后台传输图片
- 2022年下半年软考初级程序员备考
- Leetcode 113. path sum II
- 基于百问网IMX6ULL_PRO开发板驱动AP3216实验
- Mlx90640 infrared thermal imager temperature sensor module development notes (V)
- 0716RHCSA
- The interviewer asked me: how much do you know about MySQL's storage engine?
- 卷积神经网络模型之——AlexNet网络结构与代码实现
- 基于百问网IMX6ULL_PRO开发板移植LCD多点触摸驱动(GT911)
猜你喜欢

领域驱动模型设计与微服务架构落地-模型设计
![[Video] Markov chain Monte Carlo method MCMC principle and R language implementation | data sharing](/img/20/bb43ab1bc447b519c3b1de0f809b31.png)
[Video] Markov chain Monte Carlo method MCMC principle and R language implementation | data sharing

0715RHCSA

How to refactor embedded code?

Django 2 ----- database and admin

Programmer growth chapter 27: how to evaluate requirements priorities?

【AI4Code】《IntelliCode Compose: Code Generation using Transformer》 ESEC/FSE 2020

Excel录制宏

电脑里一辈子都不想删的神仙软件

Numpy简介和特点(一)
随机推荐
Azure Devops(十四) 使用Azure的私有Nuget仓库
Convolutional neural network model -- lenet network structure and code implementation
Brpc source code analysis (III) -- the mechanism of requesting other servers and writing data to sockets
【服务器数据恢复】HP EVA服务器存储RAID信息断电丢失的数据恢复
并发编程之阻塞队列
若依如何实现用户免密登录配置方法?
Excel add key run macro
二叉树基本知识
G027-OP-INS-RHEL-04 RedHat OpenStack 创建自定义的QCOW2格式镜像
Introduction and features of numpy (I)
面试官问我:Mysql的存储引擎你了解多少?
Convolutional neural network model -- googlenet network structure and code implementation
我的创作纪念日
业务可视化-让你的流程图'Run'起来(3.分支选择&跨语言分布式运行节点)
【AI4Code】《Unified Pre-training for Program Understanding and Generation》 NAACL 2021
Simple understanding of flow
hcip第七天笔记
为提高效率使用ParallelStream竟出现各种问题
Discussion on principle and application technology of MLIR
Mlx90640 infrared thermal imager temperature sensor module development notes (V)