λ¬Έμ
https://www.acmicpc.net/problem/1874
νμ΄
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
public class μ€νμμ΄ {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
Stack<Integer> stack = new Stack<>();
int n = Integer.parseInt(br.readLine());
int start = 0;
while(n-- > 0){
int value = Integer.parseInt(br.readLine());
if(value > start){
for(int i=start+1; i<=value; i++){
stack.push(i);
sb.append('+').append('\n');
}
start = value;
}
else if(stack.peek() != value){
System.out.println("NO");
return;
}
stack.pop();
sb.append("-").append("\n");
}
System.out.println(sb);
}
}
'ποΈ Algorithm > π© λ°±μ€' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
π© [λ°±μ€] [Java] [Silver3] 14501λ²_ν΄μ¬ (0) | 2024.04.05 |
---|---|
π© [λ°±μ€] [Java] [Silver3] 1966λ²_νλ¦°ν° ν (0) | 2024.01.12 |
π© [λ°±μ€] [Java] [Silver4] 10866_λ± (1) | 2024.01.10 |
π© [λ°±μ€] [Java] [Silver2] 1260λ²_DFSμ BFS (0) | 2024.01.08 |
π© [λ°±μ€] [Java] [Silver5] 2941λ²_ν¬λ‘μν°μ μνλ²³ (0) | 2023.12.10 |