UVA673 平衡的括号
  • 板块学术版
  • 楼主Horizon20182201
  • 当前回复8
  • 已保存回复8
  • 发布时间2020/6/25 17:00
  • 上次更新2023/11/7 00:05:41
查看原帖
UVA673 平衡的括号
206124
Horizon20182201楼主2020/6/25 17:00

题目传送门

一道好题呢

可我错了呢

样例是对的,我自己编的样例也是对的

#include<bits/stdc++.h>
using namespace std;

string a;
stack<char>s; 
int n,x;
bool flag; 

int main()
{
	cin>>x;
	for (int j=1;j<=x;j++)
	{
		while (!s.empty())  s.pop();
    	flag=true;
		cin>>a;
		n=a.size();
		for (int i=0;i<n;i++)
		{
			if (a[i]=='('||a[i]=='[')
			  s.push(a[i]);
			else
			{
				if (a[i]==')')
				{
					if (!s.empty()&&s.top()=='(')
					  s.pop();
					else
					{
						//cout<<"No"<<endl;
						flag=false;
						//break;
					}
				}
				if (a[i]==']')
				{
					if (!s.empty()&&s.top()=='[')
					  s.pop();
					else
					{
						//cout<<"No"<<endl;
						flag=false;
						//break;
					}
				}
			}
		}
		if (!s.empty())
    	  flag=false;
    	if (flag)
    	  cout<<"Yes"<<endl;
    	else
    	  cout<<"No"<<endl;
	}
	return 0;
}

我没救了,望各位大佬能帮忙

2020/6/25 17:00
加载中...