https://www.acmicpc.net/problem/1927
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.PriorityQueue;
public class Main {
public static void main(String[] args) throws Exception {
int N, X;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
N = Integer.parseInt(br.readLine());
PriorityQueue pq = new PriorityQueue<Integer>();
for(int i=0; i<N; i++){
X = Integer.parseInt(br.readLine());
if(X==0){
if(pq.peek() == null){
System.out.println(0);
}
else{
System.out.println(pq.poll());
}
}
else{
pq.add(X);
}
}
}
}
'IT칼럼 > JAVA' 카테고리의 다른 글
Comparable vs Comparator (0) | 2018.11.04 |
---|---|
BigInteger, BigDecimal example (0) | 2018.11.04 |
StringBuilder example (0) | 2018.11.03 |
StringTokenizer example (0) | 2018.11.03 |
BufferedReader example (0) | 2018.11.02 |