problem
solution
codes
#include<iostream>
#include<stack>
#include<string>
using namespace std;
int main(){
stack<char>s;
string str;
cin>>str;
bool flag =
1;
for(
int i =
0; i < str.size(); i++){
if(str[i] ==
'(')s.push(
'(');
else if(str[i] ==
')' && !s.empty())s.pop();
else if(str[i] ==
')' && s.empty()){ flag =
0;
break; }
}
if(s.empty() && flag)
cout<<
"YES\n";
else cout<<
"NO\n";
return 0;
}
转载请注明原文地址: https://www.6miu.com/read-2612375.html