https://www.acmicpc.net/problem/10818
1๋ฒํ์ด
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int main() {
int N;
cin >> N;
priority_queue<int, vector<int>, greater<int>>pq1; //์์ ์์๋๋ก
priority_queue<int, vector<int>,less<int>>pq2; //ํฐ ์์๋๋ก
for (int i = 0; i < N; i++) {
int number;
cin >> number;
pq1.push(number);
pq2.push(number);
}
cout << pq1.top() <<"\n"<< pq2.top();
}
2๋ฒํ์ด
#include <iostream>
#include<vector>
using namespace std;
int main() {
int N;
cin >> N;
vector<int> v;
for (int i = 0; i < N; i++) {
int number;
cin >> number;
v.push_back(number);
}
int max = v[0];
int min = v[0];
for (int i = 0; i < N; i++) {
if (max <= v[i]) max = v[i];
if (min >= v[i]) min = v[i];
}
cout << min << " " << max;
}
'Algorithm ๐ง๐ปโ๐ป > ๋ฐฑ์ค(BOJ)' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค,c++] 10822๋ฒ - ๋ํ๊ธฐ (0) | 2021.10.24 |
---|---|
[๋ฐฑ์ค,c++] 10820๋ฒ - ๋ฌธ์์ด ๋ถ์ (0) | 2021.10.24 |
[๋ฐฑ์ค,c++] 10819๋ฒ - ์ฐจ์ด๋ฅผ ์ต๋๋ก (0) | 2021.10.24 |
[๋ฐฑ์ค,c++] 10817๋ฒ - ์ธ ์ (0) | 2021.10.24 |
[๋ฐฑ์ค,c++] 10816๋ฒ - ์ซ์์นด๋ 2 (0) | 2021.10.24 |
[๋ฐฑ์ค,c++] 10815๋ฒ - ์ซ์์นด๋ (0) | 2021.10.24 |
๋๊ธ