当前位置:网站首页>Brush questions - Luogu -p1152 happy jump
Brush questions - Luogu -p1152 happy jump
2022-07-25 13:47:00 【Song Xiangshang_ UP】
P1152 Happy jump -C Language
1、 subject

2、 The problem solving process
result :
Code :
// Luogu P1152 Happy jump
#include <stdio.h>
#define NUM 1000//1≤n≤1000
int main() {
int n;//n Elements
int a[NUM];//n An integer array of elements
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);// The absolute value
j++;
}
}
/* printf(" The data of the difference array is :\n"); for (i = 0; i < n-1; i++) {// after n-1 Number of differences printf(" %d ", d_value[i]); }*/
int k = n - 1;
// Use bubble sorting to determine whether there are duplicate values , And judge the endpoints at both ends
for (i = 0; i < k-1 ; i++) {
// Conduct k-1 Secondary effervescence
for (j = 1; j <k; j++) {
if (d_value[j] == d_value[j - 1]) {
printf("Not jolly");// Jump not in line with joy
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 The data of the sorted difference array is :\n"); for (i = 0; i < n-1; i++) { printf(" %d ", d_value[i]); } printf("\n");*/
if (d_value[0] != 1) {
printf("Not jolly");// Jump not in line with joy
}
else if(d_value[n - 2] != (n - 1)){
printf("Not jolly");// Jump not in line with joy
}
else {
printf("Jolly");// Jump in line with joy
}
/* if ((d_value[0] == 1) & (d_value[n - 2] == n - 1)) { printf("Jolly");// Jump in line with joy } else { printf("Not jolly");// Jump not in line with joy }*/
return 0;
}
边栏推荐
猜你喜欢

Leetcode202 --- Happy number

2022全球开发者中,你的收入排多少?

"Digital security" alert NFT's seven Scams

刷题-洛谷-P1059 明明的随机数

The interviewer asked me: how much do you know about MySQL's storage engine?

G027-op-ins-rhel-04 RedHat openstack creates a customized qcow2 format image

0716RHCSA

Introduction to jupyter notebook
[email protected] (using password:YES)"/>The simplest solution of the whole network 1045 access denied for user [email protected] (using password:YES)

安装mujoco报错:distutils.errors.DistutilsExecError: command ‘gcc‘ failed with exit status 1
随机推荐
Excel record macro
手写jdbc的使用步骤?
职场「数字人」不吃不睡007工作制,你「卷」得过它们吗?
VIM basic operation summary
leetcode202---快乐数
mujoco_ Py Chinese document
MXNet对DenseNet(稠密连接网络)的实现
Install oh my Zsh
@wrap 装饰器
刷题-洛谷-P1146 硬币翻转
Audio and video technology development weekly | 255
刷题-洛谷-P1089 津津的储蓄计划
How to refactor embedded code?
Based on Baiwen imx6ull_ Pro development board transplants LCD multi touch driver (gt911)
Basic knowledge of binary tree
From input URL to web page display
伯克利博士『机器学习工程』大实话;AI副总裁『2022 ML就业市场』分析;半导体创业公司大列表;大规模视频人脸属性数据集;前沿论文 | ShowMeAI资讯日报
Applet enterprise red envelope function
高版本MySQL服务端安装不上怎么办,忘记密码(MySQL8.0.29)?
I2C can also be powered on by bus!