You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

22 lines
565 B

#include <bits/stdc++.h>
using namespace std;
const int N = 110;
int a[N];
// a[0] a[1] a[2] .... a[n] a[n+1]
// [1~3)
//[1~10] 左闭右闭 1,2,3,4,5,6,7,8,9,10
//(1~10) 左开右开 2,3,4,5,6,7,8,9
//[1~10) 左闭右开 1,2,3,4,5,6,7,8,9
int main() {
int n;
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
//排序 STL,从哪个位置开始,到哪个位置结束,从小向大排序
sort(a + 1, a + 1 + n); //右为开区间
// 起点 起点+长度
cout << a[n] - a[1] << endl;
return 0;
}