-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStackSeq.java
More file actions
40 lines (33 loc) · 774 Bytes
/
StackSeq.java
File metadata and controls
40 lines (33 loc) · 774 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
34
35
36
37
38
39
40
package CodeTest;
import java.util.ArrayList;
import java.util.Scanner;
import java.util.Stack;
//백준 1874번
//스택
public class StackSeq {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Stack<Integer> stack = new Stack<>();
ArrayList<String> ans = new ArrayList<>();
int n = sc.nextInt();
int i=1;
for(int count=1;count<n+1;count++){
int input = sc.nextInt();
while(input >= i){
stack.push(i++);
ans.add("+");
}
if(!stack.empty() && stack.peek().equals(input)){
stack.pop();
ans.add("-");
}
}
if (stack.empty()) {
for (String s : ans) {
System.out.println(s);
}
} else {
System.out.println("NO");
}
}
}