tj
2025-08-09 11:36:48
发布于:四川
0阅读
0回复
0点赞
//判断括号是否匹配
#include<bits/stdc++.h>
using namespace std;
char s1[265];
int TOP;//栈顶元素
//入栈操作
void push(char x){
s1[++TOP] = x;
}
//出栈操作
void pop(){
--TOP;
}
//判断是否为空
bool empty(){
return TOP == 0;
}
int main(){
string s;
getline(cin,s);
for(int i=0;i<s.size();i++){
if(s[i]=='('){
push(s[i]);
}
else if(s[i] == ')'){
if(emtpy()){
cout<<"NO";
return 0;
}
else{
pop();//出栈
}
}
else if(s[i] == '@'){
break;
}
}
if(empty()) cout<<"YES";
else cout<<"NO";
return 0;
}
这里空空如也
有帮助,赞一个