Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 31 |
Tags
- hdl
- 정보처리기사
- 정처기
- amba
- 리눅스
- 실기
- Zynq
- SQL
- 코딩테스트
- vitis
- Xilinx
- linux
- FPGA
- verilog
- boj
- verilog HDL
- axi
- AMBA BUS
- Beakjoon
- Bus
- C++
- 자격증
- UNIX
- Vivado
- Backjoon
- baekjoon
- java
- HDLBits
- chip2chip
- 백준
Archives
- Today
- Total
Hueestory
[11286] 절댓값 힙 (C++) 본문
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
struct compare {
bool operator()(int n1, int n2) {
int abs1 = abs(n1);
int abs2 = abs(n2);
if (abs1 == abs2) {
return n1 > n2;
}
else {
return abs1 > abs2;
}
}
};
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n; cin >> n;
priority_queue<int, vector<int>, compare> q;
for (int i = 0; i < n; i++) {
int input; cin >> input;
if (input == 0) {
if (q.empty()) {
cout << "0\n";
}
else {
cout << q.top() << "\n";
q.pop();
}
}
else {
q.push(input);
}
}
}
1. priority queue에 0을 정수를 입력받음
2. 0이 입력되면 queue에 있는 정수 중 절댓값이 가장 작은 수를 출력, 만약 음수와 양수가 있다면 음수부터 출력
3. 처음 입력받은 n번 만큼 출력 후 종료
'PS(중단) > BOJ' 카테고리의 다른 글
[1377] 버블 소트 (C++) (0) | 2024.04.23 |
---|---|
[2750] 수 정렬하기 (C++) (0) | 2024.04.23 |
[2164] 카드2 (C++) (0) | 2024.04.22 |
[17298] 오큰수 (C++) (0) | 2024.04.22 |
[1874] 스택 수열 (C++) (0) | 2024.04.22 |
Comments