括弧匹配检验

时间:2022-05-07
本文章向大家介绍括弧匹配检验,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
#include<iostream>
#include<cstring> 
#include<cstdio>
using namespace std;
char a[10001];//( )
char b[10001];
char c[10001];
int main()
{
	int top=0;
	int top_b=0;
	gets(c);
	int l=strlen(c);
	for(int i=0;i<=l;i++)
	{
		if(c[i]=='(')
		{
			top++;
			a[top]='(';
		}
		else if(c[i]==')')
		{
			if(a[top-1]=='(')
			top=top-2;
		 } 
		else if(c[i]=='[')
		{
			top++;
			a[top]='[';
		}
		else if(c[i]==']')
		{
			if(a[top-1]=='[')
			//top--;
			top=top-2;
		}
	}
	if(top==0)
	{
		cout<<"Yes";
	}
	else 
	cout<<"Wrong";
	return 0;
}