-
Notifications
You must be signed in to change notification settings - Fork 3
/
1062.cpp
54 lines (49 loc) · 1.06 KB
/
1062.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
50
51
52
53
54
#include <iostream>
#include <vector>
#include <stack>
using namespace std;
int main()
{
int n;
bool finish;
while (1)
{
finish = false;
cin >> n;
if (n == 0)
break;
while (!finish)
{
int count = 0;
vector<int> aux;
int v;
for (int i = 0; i < n; i++)
{
cin >> v;
if (v == 0)
{
finish = true;
break;
}
aux.push_back(v);
}
if (finish)
break;
stack<int> sta;
int i = 0;
for (int j = 1; j <= n; j++)
{
sta.push(j);
while (sta.size() && sta.top() == aux[i])
{
count++;
i++;
sta.pop();
}
}
cout << ((count == aux.size()) ? "Yes" : "No") << endl;
}
cout << endl;
}
return 0;
}