题解
2023-08-01 11:46:23
发布于:北京
0阅读
0回复
0点赞
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	stack <char> s;
	string str;
	cin>>str;
	
	for(int i = 0; i < str.length(); i++)
	{
		if(str[i] == '(')
			s.push('(');
		if(str[i] == ')')
		{
			if(s.empty())
			{
				cout<<"NO";
				return 0;
			}
			if(s.top() == '(')
				s.pop();
			else
			{
				cout<<"NO";
				return 0;
			}
		}
	}
	if(s.empty())
		cout<<"YES";
	else
		cout<<"NO";
    return 0;
}
这里空空如也

有帮助,赞一个