- 数据结构
cccc
- 2025-7-8 11:51:53 @
#include <bits/stdc++.h>
#include <stack>
using namespace std;
bool isMatched(string s) {
stack<char> st;
for (char c : s) {
if (c == '(' || c == '[') {
st.push(c);
} else if (c == ')') {
if (st.empty() || st.top() != '(') return false;
st.pop();
} else if (c == ']') {
if (st.empty() || st.top() != '[') return false;
st.pop();
}
}
return st.empty();
}
int main() {
string s;
cin >> s;
cout << (isMatched(s) ? "yes" : "no");
return 0;
}
1 条评论
-
徐涵凇 LV 6 @ 2025-7-8 15:51:04
一眼AI
- 1