#include<iostream>
#include<stack>
using namespace std;
int main()
{
int n,b,j,count;
int a[1005];
stack<int>S; //记得清空
cin>>n;
while(n!=0)
{
cin>>b;
while(b!=0)
{
count=1;
a[0]=b;
for(j=1;j<n;j++)
{
cin>>b;
a[j]=b;
}
j=0;
while(count<=n)
{
S.push(count);
if(count==a[j])
{
S.pop();
j++;
}
count++;
}
while(!S.empty())
{
count=S.top();
if(count==a[j])
{
S.pop();
j++;
}
else
break;
}
if(S.empty())
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;
cin>>b;
while(!S.empty())
S.pop();
}
cin>>n;
if(n!=0)
cout<<endl;
}
return 0;
}
poj 1363 火车进站问题,栈的基本应用
最新推荐文章于 2021-02-02 18:11:01 发布