Skip to content

Commit

Permalink
Feat: Add solution of #118
Browse files Browse the repository at this point in the history
  • Loading branch information
Dltmd202 committed Jul 8, 2022
1 parent ea55c79 commit 4e2bb25
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/BaekJoon/Dltmd202/1874/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;

public class Main {
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static StringBuilder sb = new StringBuilder();

public static void main(String[] args) throws IOException {
int n = Integer.parseInt(br.readLine());

int[] data = new int[n];
for (int i = 0; i < n; i++) {
data[i] = Integer.parseInt(br.readLine());
}

make(n, data);
}

private static void make(int n, int[] data) {
Stack<Integer> stack = new Stack<>();
int cursor = 1;

try {
for (int i = 0; i < n; i++) {
if (stack.isEmpty() || stack.peek() < data[i]) {
for (int j = cursor; j <= data[i]; j++) {
stack.push(j);
sb.append("+\n");
}
cursor = data[i] + 1;
}
while (!stack.isEmpty() && stack.peek() >= data[i]) {
if(stack.pop() > data[i]) throw new RuntimeException();
sb.append("-\n");
}
}
System.out.println(sb.toString().trim());
}catch (Exception e){
System.out.println("NO");
}
}
}

0 comments on commit 4e2bb25

Please sign in to comment.