코테 기초
if ~ else : boolean 스위치를 만들어두고 사용
서버관리자 페페
2022. 12. 6. 23:36
possibility를 true로 켜져 있게 놔두고,
별 이상이 없으면 나중에 조건문이 실행되게 함
특별한 경우가 생길 때만, switch 전환 및 break
import java.util.Scanner;
import java.util.Stack;
public class Main {
public static void main(String[] args) {
// ISC - L1
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
// L2 ~
int[] A = new int[N];
for (int i = 0; i < N; i++) {
A[i] = sc.nextInt();
}
Stack<Integer> stack = new Stack<>();
StringBuffer marker = new StringBuffer();
int num = 1;
boolean possibility = true;
for (int i = 0; i < A.length; i++) {
if (num <= A[i]) {
while (num <= A[i]) {
stack.push(num++);
marker.append("+\n");
}
stack.pop();
marker.append("-\n");
} else {
int n = stack.pop();
if (n > A[i]) {
System.out.println("NO");
possibility = false;
break;
} else {
marker.append("-\n");
}
}
}
if (possibility)
System.out.println(marker.toString());
}
}