-
Notifications
You must be signed in to change notification settings - Fork 6
/
지한얼.java
46 lines (37 loc) · 1.05 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
import java.util.*;
import java.io.*;
//속도가 2배 이상차이 ㄷㄷ
public class 지한얼{
// public static final Scanner sc = new Scanner(System.in);
public static void main(String[] args) throws IOException {
BufferedReader bf1 = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.valueOf(bf1.readLine());
int data[] = new int[n];
for(int i=0; i<n;i++) {
data[i] =Integer.valueOf(bf1.readLine());
}
Stack<Integer> stack = new Stack<>();
StringBuffer bf = new StringBuffer();
int asc =1;
for (int i=0; i<n;i++) { //n번까지
if(data[i]>=asc) {
while(data[i]>=asc) {
stack.push(asc++);
bf.append("+\n");
}
stack.pop();
bf.append("-\n");
}else {
if(stack.peek()!=data[i]) {
System.out.println("NO");
return;
}
else {
stack.pop();
bf.append("-\n");
}
}
}
System.out.println(bf.toString());
}
}