-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSTPAR.cpp
More file actions
55 lines (54 loc) · 806 Bytes
/
STPAR.cpp
File metadata and controls
55 lines (54 loc) · 806 Bytes
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
//#include<bits/stdc++.h>
#include<iostream>
#include<stack>
using namespace std;
int main(){
int n;
cin>>n;
while(n!=0){
stack<int> st,st1,st2;
int a[n];
for (int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=n;i>=1;i--)
st.push(a[i]);
int j=1;
for(int i=1;!st.empty();i++){
if(!st.empty() && st.top()==j){
st2.push(st.top());
j++;
st.pop();
}
else if(!st1.empty() && st1.top()==j ){
st2.push(st1.top());
st1.pop();
j++;
}
else{
st1.push(st.top());
st.pop();
}
}
while(!st1.empty()){
st2.push(st1.top());
st1.pop();
}
int k=n,f=0;
while(!st2.empty()){
if(st2.top()==k)
k=k-1;
else{
f=1;
break;
}
st2.pop();
}
if(f==0)
cout<<"yes"<<endl;
else
cout<<"no"<<endl;
cin>>n;
}
return 0;
}