Describe
Given a sequence of non-negative integers of length n, calculate the maximum span value of a series (maximum span value = maximum value minus minimum value).
Input
A
total of 2 rows, the number of the first action sequence N (1 <= n <= 1000), the second behavior sequence of n not more than 1000 non-negative integers, integers separated by a space.
Output
the output line that represents the maximum span value for the sequence.
Sample input
63 0 8 7 5 9
Sample output
9
This is the first sign-in question, directly on the code.
#include <iostream>using namespace Std;int main () { int n; int a[1000]; cin>>n; for (int i=0;i<n;i++) { cin>>a[i]; } int max=a[0]; int min=a[0]; for (int i=0;i<n;i++) { if (A[i]>max) { max=a[i]; } if (a[i]<min) { min=a[i]; } } cout<<max-min<<endl; return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
2015 Beijing University of Software engineering excellent college students summer camp on the machine test---A: integer sequence element maximum span value