-
Notifications
You must be signed in to change notification settings - Fork 2
/
STPAR - Street Parade.cpp
78 lines (64 loc) · 1.48 KB
/
STPAR - Street Parade.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
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
while(1)
{
long long n,i,j,k;
cin>>n;
if(n==0)
break;
stack<int> s1,s2;
int a[n];
while(!s1.empty())
s1.pop();
while(!s2.empty())
s2.pop();
for(i=0; i<n; i++)
cin>>a[i];
for(i=0; i<n; i++)
s1.push(a[n-1-i]);
i=1;
k=1;
while(i<n)
{
if(s1.empty()!=1)
{
if(s1.top()!=i && s2.empty()==1)
{
s2.push(s1.top());
s1.pop();
}
else if(s1.top()!=i && s2.top()!=i)
{
s2.push(s1.top());
s1.pop();
}
else if(s1.top()==i)
{
s1.pop();
i++;
}
else if(s2.top()==i && s2.empty()!=1)
{
s2.pop();
i++;
}
}
else if(s2.top()==i)
{
s2.pop();
i++;
}
else if(s2.top()!=i)
{
cout<<"no\n";
k=0;
break;
}
}
if(k!=0)
cout<<"yes\n";
}
}