当前位置:网站首页>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;
}边栏推荐
- B站做短视频,学抖音死,学YouTube生?
- 爱可可AI前沿推介(7.5)
- 12 MySQL interview questions that you must chew through to enter Alibaba
- I include of spring and Autumn
- wyt 。。
- How to introduce devsecops into enterprises?
- swiper. JS to achieve barrage effect
- sql server char nchar varchar和nvarchar的区别
- Object. defineProperty() - VS - new Proxy()
- Live broadcast preview | how to implement Devops with automatic tools (welfare at the end of the article)
猜你喜欢

wxml2canvas

社区团购撤城“后遗症”

Bugku's eyes are not real

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

D-snow halo solution

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

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

keep-alive

Garbage collection mechanism of PHP (theoretical questions of PHP interview)

Thymeleaf uses background custom tool classes to process text
随机推荐
keep-alive
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
Ionic Cordova project modification plug-in
wyt 。。
The difference between SQL Server char nchar varchar and nvarchar
Usage and usage instructions of JDBC connection pool
Appium自动化测试基础 — APPium基础操作API(二)
OSI 七层模型
Number protection AXB function! (essence)
可转债打新在哪里操作开户是更安全可靠的呢
Leetcode: Shortest Word Distance II
当代人的水焦虑:好水究竟在哪里?
Reasons and solutions for redis cache penetration and cache avalanche
Bugku telnet
episodic和batch的定义
爱可可AI前沿推介(7.5)
Severlet learning foundation
Crud de MySQL
No one consults when doing research and does not communicate with students. UNC assistant professor has a two-year history of teaching struggle
First PR notes