P5724 【深基4.習5】求極差

在這裏插入圖片描述

使用sort排序即可

詳細請轉:C++ STL sort函數 排序

AC代碼:

#include<bits/stdc++.h>

using namespace std;

int main(){
	int n;
	cin >> n;
	int arr[n];
	for(int i=0; i<n; i++){
		cin >> arr[i];
	}
	
	sort(arr,arr+n);
	
	cout << arr[n-1]-arr[0];
	
	return 0;
} 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章