๋ฐฑ์ค 1927: ์ต์ ํ
https://www.acmicpc.net/problem/1927
-> ๋ฐฐ์ด์ ํฌ๊ธฐ N์ ์ ๋ ฅ๋ฐ๋๋ค.
-> ๋ฐฐ์ด์ ๋ํ ์ ๋ณด ๊ฐ x๋ฅผ ์ ๋ ฅ๋ฐ๋๋ค.
-> x๊ฐ 0์ด ์๋ ์์ฐ์์ผ ๊ฒฝ์ฐ์๋ ๋ฐฐ์ด์ ๊ทธ ๊ฐ์ ์ถ๊ฐํด์ค๋ค
-> 0์ ์ ๋ ฅํ๋ค๋ฉด ๋ฐฐ์ด์์ ๊ฐ์ฅ ์์ ์๋ฅผ ์ถ๋ ฅํด์ฃผ๊ณ ,๊ทธ ๊ฐ์ ์ ๊ฑฐํด์ค๋ค.
// ๋จ, ๋ฐฐ์ด์ ๊ฐ์ด ์์ ๊ฒฝ์ฐ๋ 0์ ์ถ๋ ฅํด์ค๋ค
๋ณด์๋ง์ ์ ์ ํ์๋ ์ต๋ ํ๊ณผ ๋งค~~~~~์ฐ ๋น์ทํ ๊ฒ ๊ฐ์๋ค.
์ค์ํ ๊ฒ์ ์ ์๋ ๊ฐ์ฅ ํฐ ์๊ฐ top์ ์ค๊ฒ ํ๋ ๋ด๋ฆผ์ฐจ์ ๋ฐฐ์ด์ด์๋ค๋ฉด,
์ด๋ฒ์๋ ์์์๊ฐ top์ ์ค๊ฒํ๋ ์ค๋ฆ์ฐจ์ ๋ฐฐ์ด์ด๋ผ๋ ๊ฒ์ด๋ค! (์ฐธ๊ณ ๋ก default๊ฐ ๋ด๋ฆผ์ฐจ์์)
๊ทธ๋ฐ๋ฐ ๊ณต๋ถ๋ฅผ ์ ๋๋ก ์ํด์..์ธ์ง ์ค๋ฆ์ฐจ์ ๋ฐฐ์ด์ ์ ์ธํ๋ ๋ฒ์ ๋ชจ๋ฅด๊ฒ ์ด์ ๊ตฌ๊ธ๋งํ๋ค.
์ต๋ ํ: https://mnzy.tistory.com/manage/newpost/17?type=post&returnURL=https%3A%2F%2Fmnzy.tistory.com%2F17%3Fcategory%3D1010434
์ค๋ฆ์ฐจ์ ๋ฐฐ์ด ์ ์ธ ์ฐธ๊ณ : https://ssinee.tistory.com/entry/%EB%B0%B1%EC%A4%801927%EB%B2%88-%EC%B5%9C%EC%86%8C-%ED%9E%99?category=440812
priority_queue ์ค๋ฆ์ฐจ์ ๋ฐฐ์ด ์ ์ธ: priority_queue<int, vector<int>, greater<int>> pq;
// ์ ํํ ์ ์ ๋ฌ๋ ๊ฑด์ง ๋ชจ๋ฅด๊ฒ ์.. ๋์ค์ ์ ๋๋ก ์ฐพ์๋ณด๊ณ ๊ณต๋ถ ์์
#include <iostream>
#include <queue>
using namespace std;
int main() {
int N;
priority_queue<int, vector<int>, greater<int>> pq;
cin.tie(NULL);
ios_base::sync_with_stdio(false);
cin >> N;
for (int i = 0; i < N; i++) {
int x;
cin >> x;
if (x == 0) {
if (pq.empty()) {
cout << 0 << "\n";
}
else {
cout << pq.top() << "\n";
pq.pop();
}
}
else {
pq.push(x);
}
}
return 0;
-> for๋ฌธ์ ํตํด์ N๋ฒ ๋ฐ๋ณตํ ์ ์๊ฒ ํด์ฃผ์๊ณ if๋ฌธ์ ํตํด 0๊ณผ ๊ด๋ จ๋ ์กฐ๊ฑด๋ค์ ๋ง์กฑ์์ผ์ฃผ์๋ค.
-> ํจ์๋ค์ queue๋ผ์ด๋ธ๋ฌ๋ฆฌ ๋ด์ฅ ํจ์ ์ด์ฉ(top(),pop() ๋ฑ..)
์ค๋ฆ์ฐจ์ ๋ฐฐ์ด ์ ์ธ์ ์ ์ธํ๊ณ ๋ ์ต๋ ํ(https://mnzy.tistory.com/manage/newpost/17?type=post&returnURL=https%3A%2F%2Fmnzy.tistory.com%2F17%3Fcategory%3D1010434) ๊ณผ ํฌ๊ฒ ๋ค๋ฅผ ๊ฒ์ด ์์ด์
์ฝ๊ฒ ํด๊ฒฐํ ์ ์์๋ค!