用数组表示栈的输入输出
#include<stdio.h>`在这里插入代码片`
int size, len;
int check(void)
{
int i = 1, j = 0, temp, flag = 1;
int bottom = -1, top = -1;
int array[size];
array[++top] = i++;
do
{
scanf("%d",&temp); //记录第一个要输出的值
j++; //记录输入了多少次temp
if(flag == 1)
{
while(array[top] != temp || bottom == top)
{
array[++top] = i++;
if(top == size)
{ flag = 0; //到栈顶
break;
}
}
if(array[top] == temp)
{
top--;
}
}
}while(j < len);
if(bottom != top || flag == 0)
{
return 0;
}
return 1;
}
int main(void)
{
int flag, i, times;
scanf("%d %d %d",&size, &len, ×); //输入数组大小 长度 和比较次数
for(i = 0; i < times; i++)
{
if(check())
{
printf("YES\n");
}
else
{
printf("NO\n");
}
}
return 0;
}