更简单
2026-08-23 11:28:20
发布于:广东
4阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
stack<char>s;
int main(){
string s1;
cin >> s1;
for(int i = 0;i<s1.size();i++){
char ch=s1[i];
if(ch=='('||ch=='['||ch=='{'){
s.push(ch);
}else{
if(!s.empty()&&(s.top()=='('&&ch==')'||s.top()=='['&&ch==']'||s.top()=='{'&&ch=='}')){
s.pop();
}
}
}
if(s.empty()){
cout << "true";
}else{
cout << "false";
}
return 0;
}
这里空空如也







有帮助,赞一个