学过栈的都知道
2025-09-14 15:29:27
发布于:广东
5阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
int main() {
string s;
cin >> s;
stack<char> st;
for (int i = 0; i < s.size(); i++) {
char c = s[i];
if (c == '('){
st.push(')');
}
else if(c == '{'){
st.push('}');
}
else if (c == '['){
st.push(']');
}
else if (st.empty() || st.top() != c){
cout << "false";
return 0;
}
else{
st.pop();
}
}
cout << (st.empty() ? "true" : "false");
return 0;
}
这里空空如也







有帮助,赞一个