05-21 07:17
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- X윈도우
- spring
- selenium
- 리눅스 마스터 1급
- Mac
- Class
- 백준
- 리눅스
- 자바
- literal
- Operator
- Reference Type
- preprocessing
- dbms
- External Scheme
- Physical Scheme
- Java
- X.org
- Inheritance
- Binary Search
- Polymolphism
- BFS
- python
- descriptive statistics
- OOP
- systemd
- Entity Set
- 셀레니움
- Entity
- Unity
Archives
- Today
- Total
Byeol Lo
N12789 - 도키도키 간식드리미 본문
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.StringTokenizer;
import java.util.Stack;
public class Main {
static final BufferedReader BR = new BufferedReader(new InputStreamReader(System.in));
static StringTokenizer ST;
public static void main(String[] args) throws IOException{
Integer.parseInt(BR.readLine());
input();
}
private static void input() throws IOException {
Stack<Integer> newLine = new Stack<>();
int min = 0;
int target;
ST = new StringTokenizer(BR.readLine());
while(ST.hasMoreTokens()) {
target = Integer.parseInt(ST.nextToken());
if(target == min+1) {
min++;
} else {
while (!newLine.empty() && newLine.peek() == min + 1) {
min++;
newLine.pop();
}
newLine.add(target);
}
}
if(newLine.empty())
System.out.println("Nice");
else if(newLine.peek() == min+1)
System.out.println("Nice");
else
System.out.println("Sad");
}
}
'Algorithm > Stack & Queue' 카테고리의 다른 글
N24511 - queuestack (0) | 2023.12.09 |
---|---|
N2346 - 풍선 터뜨리기 (0) | 2023.12.09 |
N28279 - 덱 2 (1) | 2023.12.08 |
N28278 - 스택 2 (0) | 2023.12.08 |
Comments