当前位置:网站首页>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; }
边栏推荐
- OSI 七层模型
- 数据库学习——数据库安全性
- DVWA range clearance tutorial
- wxml2canvas
- PHP high concurrency and large traffic solution (PHP interview theory question)
- JMeter performance test: serveragent resource monitoring
- Huiyuan, 30, is going to have a new owner
- Temporary cramming before DFS examination
- No one consults when doing research and does not communicate with students. UNC assistant professor has a two-year history of teaching struggle
- Redis distributed lock principle and its implementation with PHP (2)
猜你喜欢
How to paste the contents copied by the computer into mobaxterm? How to copy and paste
CODING DevSecOps 助力金融企业跑出数字加速度
Talk about your understanding of microservices (PHP interview theory question)
Aike AI frontier promotion (7.5)
wxml2canvas
Value series solution report
qt creater断点调试程序详解
DVWA range clearance tutorial
Appium自动化测试基础 — APPium基础操作API(二)
力扣今日题-729. 我的日程安排表 I
随机推荐
D-snow halo solution
Xiao Sha's arithmetic problem solving Report
MySQL之CRUD
mapper. Comments in XML files
Where is the operation of convertible bond renewal? Is it safer and more reliable to open an account
What are CSRF, XSS, SQL injection, DDoS attack and timing attack respectively and how to prevent them (PHP interview theory question)
Good article inventory
Ecotone technology has passed ISO27001 and iso21434 safety management system certification
CODING DevSecOps 助力金融企业跑出数字加速度
Reproduce ThinkPHP 2 X Arbitrary Code Execution Vulnerability
Stop B makes short videos, learns Tiktok to die, learns YouTube to live?
I spring web upload
超越PaLM!北大硕士提出DiVeRSe,全面刷新NLP推理排行榜
OSI 七层模型
DVWA range clearance tutorial
swiper. JS to achieve barrage effect
lv_font_conv离线转换
Crud of MySQL
Appium automation test foundation - appium basic operation API (I)
How to introduce devsecops into enterprises?