#include <iostream>
#include <stack>
using namespace std;
bool check(string s) {
stack<char> st;
for (char c : s) {
if (c == '[') {
st.push(c);
} else if (c == ']' && !st.empty() && st.top() == '[') {
st.pop();
} else {
return false;
}
}
return st.empty();
}
int main() {
string ex;
getline(cin, ex);
if (check(ex)) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
}
中括号问题
最新推荐文章于 2024-08-14 12:02:23 发布