-
Notifications
You must be signed in to change notification settings - Fork 1
/
rails.java
40 lines (39 loc) · 1.16 KB
/
rails.java
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
//UVa 514
import java.io.*;
import java.util.*;
class Main {
public static void main(String[] args) throws IOException {
BufferedReader br =
new BufferedReader(new InputStreamReader(System.in));
//int l = Integer.parseInt(br.readLine());
int l;
while(Integer.parseInt(br.readLine()) != 0) {
while(true){
String[] targetS = br.readLine().split(" ");
int[] target = new int[targetS.length];
for(int i=0; i < targetS.length; i++) {
target[i] = Integer.parseInt(targetS[i]);
}
if (target[0] == 0) {
break;
}
Stack<Integer> station = new Stack<Integer>();
int targetIndex = 0;
for(int current=1; current <= target.length; current++) {
station.push(current);
while(!station.empty() && station.peek() == target[targetIndex] &&
targetIndex <= target.length) {
station.pop();
targetIndex++;
}
}
if(station.empty()) {
System.out.println("Yes");
} else {
System.out.println("No");
}
}
System.out.println();
}
}
}