-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ2493.java
More file actions
53 lines (47 loc) · 1.11 KB
/
BOJ2493.java
File metadata and controls
53 lines (47 loc) · 1.11 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package ¹éÁØ;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;
import java.util.StringTokenizer;
public class BOJ2493 {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
Stack<Node> s = new Stack<>();
StringTokenizer st = new StringTokenizer(br.readLine());
for(int i = 1; i <= N; i++) {
int M = Integer.parseInt(st.nextToken());
if(s.isEmpty()) {
System.out.print("0 ");
s.add(new Node(i, M));
}
else {
while(true) {
if(s.isEmpty()) {
System.out.print("0 ");
s.add(new Node(i, M));
break;
}
Node top = s.peek();
if(top.height < M) {
s.pop();
}
else {
System.out.print((top.num)+" ");
s.push(new Node(i, M));
break;
}
}
}
}
}
static class Node {
int num;
int height;
Node(int num, int height){
this.num = num;
this.height = height;
}
}
}