当前位置:网站首页>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;
}边栏推荐
- 记录一下树莓派搭建环境中遇到的坑。。。
- 12 MySQL interview questions that you must chew through to enter Alibaba
- MySQL表字段调整
- 一文搞定vscode编写go程序
- Common MySQL interview questions
- ICML 2022 | 探索语言模型的最佳架构和训练方法
- Codasip为RISC-V处理器系列增加Veridify安全启动功能
- Redis distributed lock principle and its implementation with PHP (1)
- 当代人的水焦虑:好水究竟在哪里?
- How can I quickly check whether there is an error after FreeSurfer runs Recon all—— Core command tail redirection
猜你喜欢

百亿按摩仪蓝海,难出巨头

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

Redis' transaction mechanism

Object. defineProperty() - VS - new Proxy()

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

Misc Basic test method and knowledge points of CTF
![P6183 [USACO10MAR] The Rock Game S](/img/f4/d8c8763c27385d759d117b515fbf0f.png)
P6183 [USACO10MAR] The Rock Game S

swiper. JS to achieve barrage effect

亿咖通科技通过ISO27001与ISO21434安全管理体系认证
随机推荐
Bugku alert
MySQL5.7的JSON基本操作
Appium自动化测试基础 — APPium基础操作API(一)
Can gbase 8A view the location of SQL statement history?
Calculate weight and comprehensive score by R entropy weight method
"Sequelae" of the withdrawal of community group purchase from the city
Your childhood happiness was contracted by it
Huiyuan, 30, is going to have a new owner
Temporary cramming before DFS examination
P6183 [USACO10MAR] The Rock Game S
episodic和batch的定义
力扣今日题-729. 我的日程安排表 I
Appium automation test foundation - appium basic operation API (II)
Severlet learning foundation
Huawei Hubble incarnation hard technology IPO harvester
Bugku's Ah Da
Ctfshow web entry explosion
亿咖通科技通过ISO27001与ISO21434安全管理体系认证
MySQL之CRUD
Array sorting num ranking merge in ascending order