문제접근![](data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==)
•
입력받을때마다 최대, 최소값을 업데이트 해주는 방식
놓쳤던 부분![](data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==)
•
for문 반복할때마다 max_val, min_val 초기화
코드![](data:image/gif;base64,R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==)
2020 KB
336 ms
#include <iostream>
#include <algorithm>
using namespace std;
int main(void)
{
int t;
int n;
int tmp;
int max_val, min_val;
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> t;
for (int i = 0; i < t; i++)
{
max_val = -1000000;
min_val = 1000000;
cin >> n;
for (int j = 0; j < n; j++)
{
cin >> tmp;
max_val = max(max_val, tmp);
min_val = min(min_val, tmp);
}
cout << min_val << " " << max_val << "\n";
}
return (0);
}
C++
복사