LCKDKS 1.2.23.69

刘嘉柚  •  16天前


E. 表达式括号匹配

#include<cstdio>#include<iomanip>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#define FX 0x3ffff
#define FY 0x2ea5

using namespace std; int n; stack s; char a[1145141]; bool check(string str){

for(char c:str){
	if(c=='(') s.push(c);
	else if(c==')'){
		if(s.empty()) return false;
		s.pop();
	}
}
return s.empty();

} int main() {

string str;
cin>>str;
if(check(str)) cout<<"YES";
else cout<<"NO";
return 0;

} ``


评论: