https://st-lab.tistory.com/263
[백준] 10818번 : 최소, 최대 - [C++]
https://www.acmicpc.net/problem/10818 10818번: 최소, 최대 첫째 줄에 정수의 개수 N (1 ≤ N ≤ 1,000,000)이 주어진다. 둘째 줄에는 N개의 정수를 공백으로 구분해서 주어진다. 모든 정수는 -1,000,000보다 크거나
st-lab.tistory.com
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n = 0;
int arr[1000000] = { 0, };
cin >> n;
for (int i = 0; i < n; ++i)
{
// 배열 입력
cin >> arr[i];
}
// 0 ~ n-1 까지 범위 정렬
sort(arr, arr+n);
cout << arr[0] << " " << arr[n - 1];
return 0;
}
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n = 0;
// min, max 초기값 설정
int min = 1000000;
int max = -1000000;
cin >> n;
int input = 0;
for (int i = 0; i < n; ++i)
{
// 입력값 입력
cin >> input;
// 입력값이 최소값보다 작다면 min = input
if (min > input)
min = input;
// 입력값이 최대값보다 크다면 max = input
if (max < input)
max = input;
}
cout << min << " " << max;
return 0;
}
'백준' 카테고리의 다른 글
백준 10810 C++ (1) | 2024.07.22 |
---|---|
백준 2562 C++ (0) | 2024.07.19 |
백준 10871 C++ (0) | 2024.07.18 |
백준 10807 C++ (0) | 2024.07.18 |
[백준 C++] 1271번 엄청난 부자2 (1) | 2024.01.04 |