-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB12789.java
More file actions
46 lines (36 loc) · 1014 Bytes
/
B12789.java
File metadata and controls
46 lines (36 loc) · 1014 Bytes
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package Practice;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Stack;
import java.util.StringTokenizer;
public class B12789 { //µµÅ°µµÅ° °£½Äµå¸®¹Ì
static int order = 1;
static Stack<Integer> S = new Stack<>();
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
int[] num = new int[N];
StringTokenizer st = new StringTokenizer(br.readLine());
for(int i = 0; i < N; i++) num[i] = Integer.parseInt(st.nextToken());
for(int i = 0; i < N; i++) {
if(num[i] == order) {
order++;
continue;
}
check_stack();
S.push(num[i]);
}
check_stack();
if(S.isEmpty()) System.out.println("Nice");
else System.out.println("Sad");
}
static void check_stack() {
while(!S.isEmpty()) {
int cur = S.peek();
if(cur != order) break;
order++;
S.pop();
}
}
}