hdu1022都过了,想不到却在这道简单的题上浪费了如此多的时间,真想骂人!
#include<stdio.h>
typedef struct
{
int b[1005];
int top;
}stack;
int Isempty(stack *s)
{
if(s->top==0)
return 1;
else
return 0;
}
void Push(stack *s,int x)
{
s->top++;
s->b[s->top]=x;
}
void Pop(stack *s)
{
s->top--;
}
int main()
{
int n,i,p,a[1005];
stack k;
stack *s;
s=&k;
while(scanf("%d",&n)&&n)
{
while(scanf("%d",&a[1])&&a[1])
{
s->top=0;
p=1;
for(i=2;i<=n;i++)
scanf("%d",&a[i]);
for(i=1;i<=n;i++)
{
if(i!=a[p])
Push(s,i);
else
{
Push(s,i); //为嘛此行换成p++就不对了??我感觉性质一样啊
while(s->b[s->top]==a[p])//天知道我找的有多辛苦
{
Pop(s);
p++;
if(Isempty(s))
break;
}
}
}
if(Isempty(s))
printf("Yes\n");
else
printf("No\n");
}
printf("\n");
}
return 0;
}