火车进站出站问题。五年前的一个不会写的作业。
使用了STL,实际上并不必要,但是为了试一下。
开始的时候对于停止条件想的不是很清楚,后来发现放进去之前先试着查一下top,并且要保证栈非空的情况下。
后来交题的时候遇到了很玄学的问题,对于
memset(B,0,sizeof(B));
真的不理解。
sizeof(int)就WA了,不加这句话也会WA,但是我觉得这句话并没有什么意义啊。这是个问题,以后也许会解决。
以下是AC代码。
#include <iostream>
#include<stack>
#include<string.h>
#include<cstdio>
using namespace std;
int B[1005] ;
int main()
{
stack<int> s;
int N = 0 ;
while(scanf("%d",&N),N)
{
while(scanf("%d",&B[1]), B[1])
{
for(int i = 2 ; i <=N ; i++)
cin >> B[i] ;
int pointout = 1 ;
for(int i=1; i<=N; i++)
{
s.push(i);
while(!s.empty()&&s.top()==B[pointout])
{
s.pop();
pointout++;
}
}
if(pointout==N+1)
cout << "Yes" << endl ;
else
cout << "No" << endl ;
memset(B,0,sizeof(B));
}
cout << endl ;
}
return 0;
}