-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ_1874.java
More file actions
33 lines (27 loc) · 905 Bytes
/
BOJ_1874.java
File metadata and controls
33 lines (27 loc) · 905 Bytes
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
import java.io.*;
import java.util.*;
public class BOJ_1874 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder("");
int n = Integer.parseInt(br.readLine());
Stack<Integer> stack = new Stack<>();
int number = 1;
for(int targetIdx = 0; targetIdx < n; targetIdx++) {
int target = Integer.parseInt(br.readLine());
while(target >= number) {
stack.push(number);
sb.append("+\n");
number++;
}
if(stack.peek() == target) {
stack.pop();
sb.append("-\n");
} else {
System.out.println("NO");
return;
}
}
System.out.println(sb);
}
}