文章
43
粉丝
180
获赞
21
访问
196.1k
#include <iostream>
#include <stack>
#include <unordered_map>
using namespace std;
int n;
string op;
stack<char> stk;
unordered_map<char, int> h = {{'{', 1}, {'[', 2}, {'(', 3},
{'}', -1}, {']', -2}, {')', -3}};
int main()
{
cin >> n;
while (cin >> op)
{
for (auto s : op)
if (h[s])
{
if (!stk.size() || h[s] > 0) stk.push(s);
else if (h[s] < 0 && h[s] + h[stk.top()] == 0) stk.pop();
else break;
}
if (!stk.size()) puts("yes");
else puts("no");
while (stk.size()) stk.pop();
}
return 0;
}
登录后发布评论
暂无评论,来抢沙发