当前位置:网站首页>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;
}边栏推荐
- Cartoon: programmers don't repair computers!
- The elimination strategy of redis
- 记录一下树莓派搭建环境中遇到的坑。。。
- 数据库学习——数据库安全性
- Ten billion massage machine blue ocean, difficult to be a giant
- Thymeleaf uses background custom tool classes to process text
- Huawei Hubble incarnation hard technology IPO harvester
- Can I pass the PMP Exam in 20 days?
- Install PHP extension spoole
- Hongmeng system -- Analysis from the perspective of business
猜你喜欢

12 MySQL interview questions that you must chew through to enter Alibaba

Common MySQL interview questions

Stop B makes short videos, learns Tiktok to die, learns YouTube to live?

Your childhood happiness was contracted by it

Creation and optimization of MySQL index

你童年的快乐,都是被它承包了

Bugku's Ping

Ctfshow web entry explosion

Nine hours, nine people, nine doors problem solving Report
![P6183 [USACO10MAR] The Rock Game S](/img/f4/d8c8763c27385d759d117b515fbf0f.png)
P6183 [USACO10MAR] The Rock Game S
随机推荐
六种常用事务解决方案,你方唱罢,我登场(没有最好只有更好)
Au - delà du PARM! La maîtrise de l'Université de Pékin propose diverse pour actualiser complètement le classement du raisonnement du NLP
F. Weights assignment for tree edges problem solving Report
Stop B makes short videos, learns Tiktok to die, learns YouTube to live?
Bugku's Eval
可转债打新在哪里操作开户是更安全可靠的呢
[brief notes] solve the problem of IDE golang code red and error reporting
记录一下树莓派搭建环境中遇到的坑。。。
Good article inventory
Surpass palm! Peking University Master proposed diverse to comprehensively refresh the NLP reasoning ranking
Mysql---- function
Garbage collection mechanism of PHP (theoretical questions of PHP interview)
你童年的快乐,都是被它承包了
Aike AI frontier promotion (7.5)
【简记】解决IDE golang 代码飘红报错
把 ”中台“ 的思想迁移到代码中去
Object. defineProperty() - VS - new Proxy()
Xiao Sha's arithmetic problem solving Report
Explanation report of the explosion
Dark horse programmer - software testing -10 stage 2-linux and database -44-57 why learn database, description of database classification relational database, description of Navicat operation data, de