标签:
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 25964 | Accepted: 10199 |
Description

Input
Output
Sample Input
5 1 2 3 4 5 5 4 1 2 3 0 6 6 5 4 3 2 1 0 0
Sample Output
Yes No Yes
代码:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <algorithm>
#include <stack>
using namespace std;
int main()
{
int n;
int i, j;
int a[1010];
stack<int>q;
while(scanf("%d", &n) && n!=0 )
{
while(scanf("%d", &a[0]) && a[0]!=0 )
{
for(i=1; i<n; i++)
{
scanf("%d", &a[i] );
}
int A=1, B=0;
int flag=1;
while(!q.empty())
{
q.pop();
}
while( B<n )
{
if(A==a[B])
{
A++; B++;
}
else if(!q.empty() && q.top()==a[B] )
{
q.pop(); B++;
}
else if(A<=n)
q.push(A++);
else
{
flag=0; break;
}
}
printf("%s\n", flag==1?"Yes":"No" );
}
printf("\n");
}
return 0;
}
poj 1363 Rails (【栈的应用】 刘汝佳的写法 *学习)
标签:
原文地址:http://www.cnblogs.com/yspworld/p/4251287.html