반응형
#include <algorithm> 의
max_element()
min_element()
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
// 리스트
int preMaxL[3] = { 100,300,400 };
int preMinL[3] = { 6,8,3 };
cout << *max_element(preMaxL, preMaxL + 3) << " " << *min_element(preMinL, preMinL + 3)<<endl;
// 벡터
vector<int> vec = { 1,2,3,4 };
cout << *max_element(vec.begin(), vec.end())<<" "<<*min_element(vec.begin(),vec.end())<<endl;
// 문자열
string word = "abcdefg";
cout << *max_element(word.begin(), word.end()) << " " << *min_element(word.begin(), word.end()) << endl;
// max중첩
cout << max(3, (max(5,6)))<< " "<<min(3,(min(5,6)));
}
400 3
4 1
g a
6 3
반응형