#include <iostream>
#include <vector> // vector
#include <algorithm> // vector의 최댓값, 최솟값을 구하기 위한 헤더
using namespace std;
int main(){
vector<int> ages; // vector 선언
int a = 0;
int n = 0; // 변수 선언 및 초기화
cin>> n; // 입력받을 값 개수
// 결과 도출
for(int i = 0; i < n; i++){
cin>> a;
ages.push_back(a);
}
// max(min)_element(const iterator begin, const iterator end)
// 배열의 시작 - 끝에서 최대(최소)의 값을 iterator로 반환
// *(포인터) 를 추가하면 실제값을 반환
int max = *max_element(ages.begin(), ages.end());
int min = *min_element(ages.begin(), ages.end());
cout<< max - min;
}
1. <algorithm> 헤더의 max(min)_element(const iterator begin, const iterator end)
- 배열의 시작 - 끝에서 최대(최소)값을 iterator로 return
- *(포인터) 를 추가하면 실제 해당 배열의 원소를 return