求助!ACM第二题,提交上去老是编译出错
程序代码:#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct stack
{
char f;
struct stack *next;
}stack;
stack *top=NULL;
void push(char A)
{
stack *t=malloc(sizeof(stack));
t->f=A;
t->next=top;
top=t;
}
int pop(char B)
{
stack *temp=top;
if(temp==NULL)return 0;
if(B==')')
{
if(temp->f=='(')
{top=top->next;return 1;}
while(temp->next!=NULL)
{
if(temp->next->f=='(')
{
temp->next=temp->next->next;
return 1;
}
temp=temp->next;
}
return 0;
}
if(B==']')
{
if(temp->f=='[')
{top=top->next;return 1;}
while(temp->next!=NULL)
{
if(temp->next->f=='[')
{
temp->next=temp->next->next;
return 1;
}
temp=temp->next;
}
return 0;
}
}
void pp()
{
int n;
char s[10000];
gets(s);
for(n=0;n<strlen(s);n++)
{
if(s[n]=='['||s[n]=='('){push(s[n]);}
if(s[n]==']'||s[n]==')'){if(pop(s[n])==0){printf("No\n");top=NULL;return;}}
}
if(top==NULL)
printf("Yes\n");
else
{printf("No\n");
top=NULL;}
return;
}
int main()
{
int n,k;
scanf("%d",&n);
getchar();
for(k=0;k<n;k++)
pp();
getchar();
return 0;
}









