当前位置:网站首页>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; }
边栏推荐
- Value series solution report
- Common PHP interview questions (1) (written PHP interview questions)
- Garbage collection mechanism of PHP (theoretical questions of PHP interview)
- Creation and optimization of MySQL index
- wyt 。。
- B站做短视频,学抖音死,学YouTube生?
- mapper.xml文件中的注释
- First PR notes
- P6183 [USACO10MAR] The Rock Game S
- Bugku's Eval
猜你喜欢
DVWA range clearance tutorial
基于OpenHarmony的智能金属探测器
Lesson 4 knowledge summary
P1451 calculate the number of cells / 1329: [example 8.2] cells
Good article inventory
亿咖通科技通过ISO27001与ISO21434安全管理体系认证
Explanation report of the explosion
MySQL----函数
P6183 [USACO10MAR] The Rock Game S
Garbage collection mechanism of PHP (theoretical questions of PHP interview)
随机推荐
How can the boss choose programmers to help me with development?
Write a go program with vscode in one article
SQL Server learning notes
Usage and usage instructions of JDBC connection pool
F. Weights assignment for tree edges problem solving Report
mapper. Comments in XML files
CODING DevSecOps 助力金融企业跑出数字加速度
Xiao Sha's arithmetic problem solving Report
【 note 】 résoudre l'erreur de code IDE golang
Misc Basic test method and knowledge points of CTF
Stop B makes short videos, learns Tiktok to die, learns YouTube to live?
queryRunner. Query method
Go learning ----- relevant knowledge of JWT
Your childhood happiness was contracted by it
sql server char nchar varchar和nvarchar的区别
CSDN I'm coming
MySQL之CRUD
ICML 2022 | 探索语言模型的最佳架构和训练方法
F. Min cost string problem solving Report
做研究无人咨询、与学生不交心,UNC助理教授两年教职挣扎史