#include <bits/stdc++.h>
using namespace std;
stack<char> s;
int num;
/**
测试用例:
2
[({})]
()[]()
*/
char trans(char a) {
if (a == ')') return '(';
if (a == ']') return '[';
if (a == '}') return '{';
return '\0';
}
int main() {
cin >> num;
string p;
//getline(cin, p);//读取末尾的指针
getchar();
while (num--) {
while (!s.empty())s.pop();
getline(cin, p);
for (int i = 0; i < p.size(); i++) {
if (s.empty()) {
s.push(p[i]);
continue;
}
if (trans(p[i]) == s.top())s.pop();
else s.push(p[i]);
}
if (s.empty())printf("Yes\n");
else printf("No\n");
}
return 0;
}
UVA673
原创
©著作权归作者所有:来自51CTO博客作者superhuanghai的原创作品,请联系作者获取转载授权,否则将追究法律责任
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
uva 673(线性表)
题解:把第一个括号放到栈里,然后看后面的一个括号是否和他匹配,如果匹配就把栈里的括号取出,否则就把当前的括号也放进栈里
uva 数据结构 g++ #include ios -
UVA-673-栈-水题
题意: 检测括号是否匹配,注意有空格
#include ios i++ 测试排序 -
【uva-673】 Parentheses Balance(括号匹配问题)
题干:You are given a string
#include ios i++ -
Uva 673 平衡的括号——栈的操作
#inclu
#include ios i++ -
NYOJ 673 悟空的难题
悟空的难题时间限制:1000 ms | 内存限制:65535 KB难度:2描述自从悟空当高排成一队。猴子们是如此
NYOJ acm 排序算法 #include #define -
STL应用——UVA673(堆栈)
分析:栈的应用,遇到右括号便弹出栈顶元素,看是否与右括号相互匹配,其余情况压入栈。 注意:本题有坑,空串空串,为此我跪了数次
#include 出栈 ios i++ 入栈 -
UVa 673 平衡的括号
题意:给出包含"()"和"[]"的括号序列,判断是否合法。 用栈来完成,注意空串就行。
#include ios 括号序列 i++ 编程