-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
42 lines (36 loc) · 1.06 KB
/
Main.java
File metadata and controls
42 lines (36 loc) · 1.06 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
import java.io.IOException;
import java.util.Scanner;
import java.util.Stack;
public class Main {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
Stack<Integer> stack = new Stack<Integer>();
StringBuilder answer = new StringBuilder();
int N = sc.nextInt();
int cnt = 1;
for(int i=1; i<N+1; i++){
int data = sc.nextInt();
while(cnt <= data){
stack.push(cnt);
cnt++;
answer.append('+');
}
if(stack.peek() == data){
stack.pop();
answer.append('-');
} else{
answer = new StringBuilder();
answer.append("NO");
break;
}
}
if(answer.toString().equals("NO")){
System.out.println(answer);
} else {
for(int i=0; i<answer.length(); i++){
System.out.println(answer.charAt(i));
}
}
sc.close();
}
}