-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2493_ํ.java
More file actions
51 lines (50 loc) ยท 1.57 KB
/
2493_ํ.java
File metadata and controls
51 lines (50 loc) ยท 1.57 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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;
import java.util.StringTokenizer;
public class Main{
static int N;
static Stack<peek_idx> stack;
static int num = 1;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
StringBuilder sb = new StringBuilder();
N = Integer.parseInt(st.nextToken());
stack = new Stack<peek_idx>();
st = new StringTokenizer(br.readLine());
peek_idx idx;
for(int i=0; i<N;i++) {
idx= new peek_idx(Integer.parseInt(st.nextToken()), num++);
if(stack.isEmpty()) {
System.out.print(0 + " ");
stack.push(idx);
} else {
while(true) {
if(stack.isEmpty()) {
sb.append(0 + " ");
stack.push(idx);
break;
}
if(stack.peek().height >= idx.height) {
sb.append(stack.peek().num + " ");
stack.push(idx);
break;
} else {
stack.pop();
}
}
}
}
System.out.println(sb);
}
}
class peek_idx{
int num;
int height;
peek_idx(int height, int num){
this.height = height;
this.num = num;
}
}