表达式括号匹配-洛谷

题目链接

#include<iostream>
#include<cstdio>
#include<queue>
using namespace std;
char a[10000];
int main()
{
	queue<int>A;
	int i=1;a[0]=getchar();
	while(a[i-1] != '@')
	{
		a[i]=getchar();
		i++;
	}
	int d=i;
int u=0;
	for(int i = 0 ;i < d;i++)
	{
		if(a[i] == '(')
		{
			A.push(a[i]);continue;	
		}
		if(	a[i] == ')')
		{
			if(A.front() == '(')
			{
				A.pop();
			}
			else{
			    printf("NO\n");return 0;
			}
		}
	}
	if(A.empty())
	{
		printf("YES\n");
	 } 
	 else{
	 	printf("NO\n");
	 }
	return 0;
}

https://www.luogu.org/problemnew/show/P1739

猜你喜欢

转载自blog.csdn.net/qq_43568078/article/details/84981790