当前位置:网站首页>刷题-洛谷-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;
}
边栏推荐
- How to realize the configuration method of user password free login?
- 剑指offer专项突击版第10天
- Design and principle of thread pool
- Prepare for 2022 csp-j1 2022 csp-s1 preliminaries video set
- Hcip day 8 notes
- Django 2 ----- 数据库与Admin
- Arrays常用方法
- MLIR原理与应用技术杂谈
- Cv2.resize function reports an error: error: (-215:assertion failed) func= 0 in function ‘cv::hal::resize‘
- Introduction and features of numpy (I)
猜你喜欢

VIM basic operation summary

0710RHCSA
详解浮点数的精度问题

Shell common script: check whether a domain name and IP address are connected

Introduction and features of numpy (I)

基于百问网IMX6ULL_PRO开发板移植LCD多点触摸驱动(GT911)
TCP的拥塞控制

What is your revenue rank among global developers in 2022?

R language GLM generalized linear model: logistic regression, Poisson regression fitting mouse clinical trial data (dose and response) examples and self-test questions
![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]
随机推荐
Shell common script: judge whether the file of the remote host exists
说说对hashcode和equals方法的理解?
Mutex lock, spin lock, read-write lock... Clarify their differences and applications
Machine learning strong foundation program 0-4: popular understanding of Occam razor and no free lunch theorem
hcip第八天笔记
Immortal software in the computer that I don't want to delete all my life
0719RHCSA
ES6 array de duplication new set()
全网最简单解决方式1045-Access denied for user [email protected](using password:YES)
Blocking queue for concurrent programming
二叉树基本知识
Shell common script: get the IP address of the network card
Shell common script: check whether a domain name and IP address are connected
Introduction to jupyter notebook
Numpy简介和特点(一)
6.27 uniapp项目历程
Excel add key run macro
Excel录制宏
Generate SQL script file by initializing the latest warehousing time of vehicle attributes
[six articles talk about scalablegnn] around www 2022 best paper PASCA