AcWing 3693. 括号匹配
原题链接
简单
作者:
故事里的大魔王
,
2025-01-13 20:08:44
,
所有人可见
,
阅读 2
#include <iostream>
#include <stack>
using namespace std;
int main() {
char ch;
stack<char> dict;
int flag = 0;
while (cin >> ch) {
if (ch == '<' || ch == '(' || ch == '{' || ch == '[') {
dict.push(ch);
}
else {
if (!dict.empty()){
if (ch == '>' && dict.top() == '<') dict.pop();
else if (ch == ')' && dict.top() == '(') dict.pop();
else if (ch == '}' && dict.top() == '{') dict.pop();
else if (ch == ']' && dict.top() == '[') dict.pop();
else break;
}
else{
flag = 1;
break;
}
}
}
if (!dict.empty() || flag) cout << "no" << endl;
else cout << "yes" << endl;
return 0;
}