-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBOJ1874.java
More file actions
40 lines (31 loc) · 711 Bytes
/
Copy pathBOJ1874.java
File metadata and controls
40 lines (31 loc) · 711 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 day2.stackQueue;
import java.util.Arrays;
import java.util.Scanner;
import java.util.Stack;
public class BOJ1874 {
public static void main(String[] args) {
Stack<Integer> stk=new Stack<>();
Scanner sc=new Scanner(System.in);
int N=sc.nextInt();
int[] arr=new int[N];
for (int i = 0; i < N; i++) {
arr[i]=sc.nextInt();
}
System.out.println(Arrays.toString(arr));
for (int i = 1; i < N+1; i++) {
if(i<arr[i-1]) {
stk.push(i);
System.out.println("+");
}
if (i==arr[i-1]) {
stk.pop();
System.out.println("-");
}
System.out.println(stk);
// if(i==arr[i-1]) {
// stk.pop();
// System.out.println("-");
// }break;
}
}
}