-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1062.cpp
84 lines (80 loc) · 1.21 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include<bits/stdc++.h>
struct no
{
int n;
struct no *prox;
};
struct pilha
{
struct no *topo;
};
void create(pilha *s)
{
s->topo=NULL;
}
void push(pilha*s, int d)
{
struct no *aux;
aux=(struct no*)malloc(sizeof(struct no));
if(aux==NULL)return ;
aux->n=d;
aux->prox=s->topo;
s->topo=aux;
}
//void pop(pilha *s, int *d)
void pop(pilha *s)
{
struct no *aux;
if(s->topo==NULL)return ;
aux=s->topo;
s->topo=(s->topo)->prox;
//*d=aux->n;
free(aux);
}
bool isEmpty(pilha s)
{
if(s.topo==NULL)return true;
return false;
}
int topt(pilha s)
{
struct no *aux = s.topo;
return aux->n;
}
using namespace std;
int main()
{
int n;
while(scanf("%d",&n),n)
{
int x;
vector<int>v;
while(scanf("%d",&x),x)
{
int ax;
v.push_back(x);
for(int i=1;i<n;i++)
{
scanf("%d",&ax);
v.push_back(ax);
}
pilha p;
create(&p);
int c=0;
for(int i=1;i<=n;i++)
{
push(&p,i);
while(!isEmpty(p) && v[c]==topt(p))
{
c++;
pop(&p);
}
}
if(isEmpty(p))printf("Yes\n");
else printf("No\n");
v.clear();
}
printf("\n");
}
return 0;
}