当前位置:网站首页>Noi / 1.5 06: element maximum span value of integer sequence
Noi / 1.5 06: element maximum span value of integer sequence
2022-07-05 15:35:00 【Graylan_】
describe
Given a length of n A sequence of nonnegative integers , Please calculate the maximum span of the sequence ( Maximum span value = The maximum minus the minimum ).
Input
altogether 2 That's ok , The number of the first behavior sequence n(1 <= n <= 1000), The second behavior sequence n No more than one. 1000 Non-negative integer , Integers are separated by a space .
Output
Output one line , Represents the maximum span value of the sequence .
The sample input
6 3 0 8 7 5 9
Sample output
9
Problem analysis : Find the maximum value by cycling , Set an intermediate value to constantly exchange the order of elements in the array , You can finally find the maximum value and lock the minimum value as the first element , That is to say a[0].
Source code :
#include <iostream>
using namespace std;
int main()
{
int n,i,j,t;
int a[1005];
cin>>n;
for(i=0;i<n;i++)
cin>>a[i];
for(j=0;j<n-1;j++)
{
for(i=0;i<n-j-1;i++)
{
if(a[i+1]<a[i])
{
t=a[i+1];
a[i+1]=a[i];
a[i]=t;
}
}
}
cout<<a[n-1]-a[0];
return 0;
}边栏推荐
- 百亿按摩仪蓝海,难出巨头
- episodic和batch的定义
- Codasip为RISC-V处理器系列增加Veridify安全启动功能
- Definition of episodic and batch
- Go learning ----- relevant knowledge of JWT
- mapper. Comments in XML files
- Ten billion massage machine blue ocean, difficult to be a giant
- Can gbase 8A view the location of SQL statement history?
- 数据库学习——数据库安全性
- Appium自动化测试基础 — APPium基础操作API(一)
猜你喜欢

Your childhood happiness was contracted by it

Advanced level of static and extern

【簡記】解决IDE golang 代碼飄紅報錯

B站做短视频,学抖音死,学YouTube生?

keep-alive

Detailed explanation of C language branch statements

Ecotone technology has passed ISO27001 and iso21434 safety management system certification

Appium automation test foundation - appium basic operation API (II)

Common PHP interview questions (1) (written PHP interview questions)

Explanation report of the explosion
随机推荐
Array sorting num ranking merge in ascending order
数学建模之层次分析法(含MATLAB代码)
华为哈勃化身硬科技IPO收割机
Common interview questions about swoole
OSI seven layer model
百亿按摩仪蓝海,难出巨头
queryRunner. Query method
Garbage collection mechanism of PHP (theoretical questions of PHP interview)
MySQL----函数
MySQL之CRUD
Creation and optimization of MySQL index
keep-alive
Usage and usage instructions of JDBC connection pool
Cartoon: programmers don't repair computers!
Bugku's eyes are not real
Bugku's steganography
Bugku alert
The elimination strategy of redis
爱可可AI前沿推介(7.5)
swiper. JS to achieve barrage effect