问题类型:STL-Stack。
03pie’s solution for [UVA-514]:
题目链接
#include<iostream>
#include<stack>
using namespace std;
const int maxn=1000+10;
int target[maxn];
int main(){
// freopen("F://inp.txt","r",stdin);
int n,first=1;
while(cin>>n&&n){
// if(first) first=!first;
// else printf("\n");
for(;;){
stack<int> s;
for(int i=1;i<=n;i++){
cin>>target[i];
if(target[1]==0) break;
}
if(target[1]==0) break;
int A=1,B=1,ok=1;
while(B<=n){
if(A==target[B]) {A++;B++;}
else if(!s.empty()&&s.top()==target[B]) {s.pop();B++;}
else if(A<=n) s.push(A++);
else {ok=0;break;}
}
printf("%s\n",ok?"Yes":"No");
}
cout<<"\n";
}
return 0;
}