https://www.acmicpc.net/problem/25556
25556번: 포스택
포닉스가 순열을 청소할 수 있으면 YES, 불가능하다면 NO를 출력한다.
www.acmicpc.net
- 알고리즘 분류 : 스택, 자료구조
- 레벨 : 레벨은 어떻게 확인하나요?
import java.util.*;
public class Main{
public static void main(String[] args){
int sizenum = 0;
boolean yesorno = true;
Stack<Integer> stack1 = new Stack<>();
Stack<Integer> stack2 = new Stack<>();
Stack<Integer> stack3 = new Stack<>();
Stack<Integer> stack4 = new Stack<>();
Scanner sc = new Scanner(System.in);
sizenum = sc.nextInt();
sc.nextLine();
int[] numArr = new int[sizenum];
String [] stringArr = sc.nextLine().split(" ");
numArr = Arrays.stream(stringArr).mapToInt(Integer::parseInt).toArray();
for(int num:numArr){
if(stack1.isEmpty() || stack1.peek() < num){
stack1.push(num);
}else if(stack2.isEmpty() || stack2.peek() < num){
stack2.push(num);
}else if(stack3.isEmpty() || stack3.peek() < num){
stack3.push(num);
}else if(stack4.isEmpty() || stack4.peek() < num){
stack4.push(num);
}else{
yesorno = false;
}
}
if(yesorno){
System.out.println("YES");
}else{
System.out.println("NO");
}
}
}
"Yes", "No" 라고 적어놔서 틀렸다.. ㅎㅎ 다시 "YES", "NO"로 수정 후 제출 완료!!
반응형
'코테 > 백준' 카테고리의 다른 글
[백준 17144번] 자바 미세먼지 안녕! lv > gold4 (0) | 2023.07.28 |
---|---|
[백준 17142번] 연구소 3 lv > gold3 자바 (0) | 2023.07.27 |
[백준 14500번] 자바 테트로미노 lv > gold4 (0) | 2023.07.26 |
[백준 14889번] 자바 스타트와 링크 lv > silver2 (0) | 2023.07.25 |
[백준 14888번] 자바 연산자 끼워넣기 lv > silver1 (0) | 2023.07.24 |