-
Notifications
You must be signed in to change notification settings - Fork 0
/
uva514.cpp
49 lines (38 loc) · 1.02 KB
/
uva514.cpp
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
#include <iostream>
#include <stack>
using namespace std;
int n;
int main(){
int a[1000],c,i,j;
while (true)
{
cin >> n;
if (n==0) break;
while(true){
cin >> a[0];
if (a[0] == 0){
cout << endl;
break;
}
for(int d = 1;d<n;++d){
cin >> a[d];
}
c = j = 0;
i = 1;
stack <int> s;
while(i <= n){
// if (c > 0 && s.top() > a[j]) break;
s.push(i++), c++;
while(!s.empty() && s.top() == a[j]){
s.pop();
j++;
if (j>=n) break;
}
// cout << "here\n";
}
if(s.empty()) cout << "Yes\n";
else cout << "No\n";
}
}
return 0;
}