文章
145
粉丝
217
获赞
21
访问
84.0k
#include <stdio.h>
#include <string.h>
int main()
{
int n,i,j = 0,k,a[100],top,flag;//a数组为标记数组,flag为标记
char s[255],tt[255],c;//tt数组为栈
scanf("%d",&n);
for(i = 0 ; i < n; i++)
{
top = -1;//栈顶指针
k = 0;
flag = 0;
scanf("%s",s);
while(s[k] != '\0')//循环判断
{
c = s[k++];
if(c == '{' || c == '[' || c == '(' || c == '<')//判断左括号优先级进行入栈
{ if(top == -1)
{
flag = 1;
tt[++top] = c;
}
else if(top != -1 && tt[top] >= c)
{
if(tt[top] == '<' && c == '(')
{
flag = 0;
break;
}
else
{
flag = 1;
tt[++top] = c;
}
}
else if(top != -1 && tt[top] <= c)
{
if(!(tt[top] == '(' && c == '<'))
{
flag = 0;
break;
}
else
{
flag = 1;
tt[++top] = c;
}
}
}
else //判断右括号与栈顶是否匹配
{
if((tt[top] == '(' && t...
登录后发布评论
暂无评论,来抢沙发