-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUva514.java
More file actions
52 lines (49 loc) · 1.53 KB
/
Copy pathUva514.java
File metadata and controls
52 lines (49 loc) · 1.53 KB
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
47
48
49
50
51
52
import java.util.*;
import java.io.*;
public class Uva514
{
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pr = new PrintWriter(System.out);
StringBuilder sb = new StringBuilder();
while(true)
{
int n = Integer.parseInt(br.readLine());
if(n==0)
break;
Stack<Integer> stack = new Stack<>();
LOOP:while (true)
{
StringTokenizer st = new StringTokenizer(br.readLine());
int max = 0 ;
boolean status = true ;
while (st.hasMoreTokens())
{
int x = Integer.parseInt(st.nextToken());
if(x==0)
break LOOP ;
if(x>max)
{
for (int i = max+1 ; i < x ; i++) {
stack.push(i);
}
max = x ;
}
else{
int y = stack.pop();
if(x!=y) {
status = false;
break ;
}
}
}
sb.append(status?"Yes\n":"No\n");
stack.clear();
}
sb.append("\n");
}
pr.print(sb.toString());
pr.close();
br.close();
}
}