1063: The maximum span value

Description] [Title
of a given length of a sequence of non-negative integer n, see the maximum span value (maximum value = maximum value minus the minimum span) calculated sequence.

[Input]
total 2 lines, sequence number n of the first row (1 ≤ n ≤ 1000), the behavior of the second sequence of n less than 1000 non-negative integer, with a space between integers.

[Output]
output line, the span represents the maximum value of the sequence.

[] Input sample
. 6
. 3. 5. 7. 8 9 0
[output] Sample
9

#include<bits/stdc++.h>
using namespace std;
#define N 1005
int a[N], mmin = 1005, mmax = -1;
int main(){
    int n;
    cin >> n;
    for(int i=1; i<=n; i++){
        cin >> a[i];
        mmax = max(mmax, a[i]);
        mmin = min(mmin, a[i]);
    }
    cout << mmax - mmin;
    return 0;
}
Published 15 original articles · won praise 10 · views 211

Guess you like

Origin blog.csdn.net/qq_39053800/article/details/104245450