File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
src/main/java/sgyj/backjun/seunggu Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change
1
+ package sgyj .backjun .seunggu ;
2
+
3
+ import java .io .BufferedReader ;
4
+ import java .io .IOException ;
5
+ import java .io .InputStreamReader ;
6
+ import java .util .PriorityQueue ;
7
+
8
+ public class Main1927 {
9
+
10
+ public static void main (String [] args ) {
11
+ try ( BufferedReader reader = new BufferedReader (new InputStreamReader (System .in ))) {
12
+ PriorityQueue <Integer > queue = new PriorityQueue <>();
13
+ int count = Integer .parseInt (reader .readLine ());
14
+ StringBuilder stringBuilder =new StringBuilder ();
15
+ for (int i =0 ; i <count ; i ++) {
16
+ int num = Integer .parseInt (reader .readLine ());
17
+ if (num == 0 ) {
18
+ if (queue .isEmpty ()) {
19
+ stringBuilder .append (0 );
20
+ } else {
21
+ stringBuilder .append (queue .poll ());
22
+ }
23
+ stringBuilder .append ("\n " );
24
+ } else {
25
+ queue .offer (num );
26
+ }
27
+ }
28
+ System .out .println (stringBuilder );
29
+ } catch (IOException e ) {
30
+ e .printStackTrace ();
31
+ }
32
+ }
33
+
34
+ }
You can’t perform that action at this time.
0 commit comments