文章
43
粉丝
180
获赞
21
访问
195.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}, {'<',4},
{'}', -1}, {']', -2}, {')', -3}, {'>',-4}};
int main()
{
cin >> n;
while (n -- )
{
cin >> op;
for (auto s : op)
{
if (!stk.size() || h[s] >= h[stk.top()]) 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;
}
登录后发布评论
暂无评论,来抢沙发