当前位置:网站首页>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;
}边栏推荐
- Install PHP extension spoole
- go语言编程规范梳理总结
- What are CSRF, XSS, SQL injection, DDoS attack and timing attack respectively and how to prevent them (PHP interview theory question)
- "Sequelae" of the withdrawal of community group purchase from the city
- Garbage collection mechanism of PHP (theoretical questions of PHP interview)
- Bugku's steganography
- Appium automation test foundation - appium basic operation API (II)
- Mysql---- function
- Ctfshow web entry explosion
- Live broadcast preview | how to implement Devops with automatic tools (welfare at the end of the article)
猜你喜欢

Huawei Hubble incarnation hard technology IPO harvester

Write a go program with vscode in one article

Bugku's Ping

I include of spring and Autumn

Appium自动化测试基础 — APPium基础操作API(二)

Aike AI frontier promotion (7.5)

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

基于OpenHarmony的智能金属探测器

Common MySQL interview questions

F. Min cost string problem solving Report
随机推荐
Xiao Sha's arithmetic problem solving Report
Codasip为RISC-V处理器系列增加Veridify安全启动功能
Good article inventory
MySQL之CRUD
Reasons and solutions for redis cache penetration and cache avalanche
Ecotone technology has passed ISO27001 and iso21434 safety management system certification
mapper. Comments in XML files
百亿按摩仪蓝海,难出巨头
DVWA range clearance tutorial
30岁汇源,要换新主人了
go学习 ------jwt的相关知识
SQL Server learning notes
Misc Basic test method and knowledge points of CTF
1330:【例8.3】最少步数
Definition of episodic and batch
Go learning ----- relevant knowledge of JWT
Bugku's steganography
Ctfshow web entry information collection
Redis distributed lock principle and its implementation with PHP (2)
Can I pass the PMP Exam in 20 days?