#문제
https://www.acmicpc.net/problem/1874
#소스코드
package stack;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Stack;
public class BOJ1874 {
public static int N;
public static Queue<Integer> que;
public static void input() throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
N = Integer.parseInt(br.readLine());
que = new LinkedList<Integer>();
for(int i = 1; i <= N; i++){
que.offer(Integer.parseInt(br.readLine()));
}
}
public static void main(String[] args) throws Exception {
input();
StringBuilder sb = new StringBuilder();
Stack<Integer> st = new Stack<Integer>();
for(int i = 1; i <= N; i++){
st.push(i);
sb.append("+\n");
while(!st.isEmpty() && st.peek().intValue() == que.peek().intValue()){
que.poll();
st.pop();
sb.append("-\n");
}
}
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
if(que.size() > 0){
bw.write("NO");
} else {
bw.write(sb.toString());
}
bw.flush();
}
}
'💡Problem Solving > BOJ' 카테고리의 다른 글
[BOJ 15900] 나무 탈출 (Java) (0) | 2021.10.21 |
---|---|
[BOJ 2056] 작업 (Java) (0) | 2021.10.20 |
[BOJ 21773] 가희와 프로세스 1 (Java) (0) | 2021.10.19 |
[BOJ 21772] 가희의 고구마 먹방 (Java) (0) | 2021.10.19 |
[BOJ 22232] 가희와 파일 탐색기 (Java) (0) | 2021.10.18 |