문제/백준_자바
183. 1927(최소 힙) - 자바
sm_hope
2022. 8. 22. 17:42
import java.util.*;
import java.io.*;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
PriorityQueue<Integer> que = new PriorityQueue<>();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < N; i++) {
int X = sc.nextInt();
if(X==0) {
if(que.isEmpty()) {
sb.append(0).append("\n");
}
else {
sb.append(que.remove()).append("\n");
}
}
else {
que.add(X);
}
}
System.out.print(sb);
}
}
문제요약
값을 입력하는데 0이면 현재 입력된 값 중에 가장 작은 값을 출력하라.(오름차순 필요)
설명
전 단계 문제를 풀었다면 매우 간단한 문제
https://smhope.tistory.com/487
182. 11279(최대 힙) - 자바
import java.util.*; import java.io.*; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); StringBuilder sb = new StringBuilder(); int N = sc.nextInt(); Priorit..
smhope.tistory.com