-
Notifications
You must be signed in to change notification settings - Fork 0
/
스택 수열.java
64 lines (46 loc) · 1.83 KB
/
스택 수열.java
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
54
55
56
57
58
59
60
61
62
63
64
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.Stack;
public class Main {
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
boolean result = true;
StringBuilder sb = new StringBuilder();
Stack<Integer> stack = new Stack<>();
int N = Integer.parseInt(br.readLine());
int cur =1;
for(int i =0; i<N; i++)
{
int n = Integer.parseInt(br.readLine());
if(n>=cur)
{
while(n>=cur)
{
stack.push(cur++);
sb.append("+\n");
}
stack.pop();
sb.append("-\n");
}
else
{
int a= stack.pop();
if(a>n)
{
System.out.println("NO");
result = false;
break;
}
else
{
sb.append("-\n");
}
}
}
if(result) System.out.println(sb);
}
}