题解
2023-09-24 11:22:31
发布于:江苏
2阅读
0回复
0点赞
#include <iostream>
#include <stack>
#include <string>
using namespace std;
bool isMatching(string expression) {
stack<char> brackets;
for (char c : expression) {
if (c == '(') {
brackets.push(c);
} else if (c == ')') {
if (brackets.empty() || brackets.top() != '(') {
return false;
}
brackets.pop();
}
}
return brackets.empty();
}
int main() {
string expression;
cin >> expression;
if (isMatching(expression)) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
return 0;
}
这里空空如也
有帮助,赞一个