forked from mintuhouse/spoj-solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
95-stpar.cpp
53 lines (52 loc) · 1.17 KB
/
95-stpar.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
#include<iostream>
#include<queue>
#include<stack>
#include<algorithm>
#include<stdio.h>
using namespace std;
int main(){
int n;
cin>>n;
while(n!=0){
int v;
queue<int> Q;
stack<int> S;
for(int i=0;i<n;i++){
cin>>v;
Q.push(v);
}
//printf("QSstart\n");
int c=1;
while(!Q.empty()||!S.empty()){
//printf("QS\n");
if(!Q.empty()&&Q.front()==c) {
//printf("Qf\n");
Q.pop();
c++;
}else{
if(!S.empty()&&S.top()==c){
//printf("Sf\n");
S.pop();
c++;
}else{
if(!Q.empty()){
//printf("Q\n");
int s=Q.front();
S.push(s);
Q.pop();
}else{
break;
}
}
}
}
if(c==n+1){
cout<<"yes"<<endl;
}else{
cout<<"no"<<endl;
}
//printf("QSend\n");
cin>>n;
}
return 0;
}