UVa 673 - Parentheses Balance
2013-04-15 14:53
295 查看
用栈进行模拟就行了,不过要考虑空行的情况,该开始就没考虑数据有空行的情况,认为不可能,WA了一次,果然没什么理所当然啊。
代码如下:
View Code
代码如下:
View Code
#include <cstdio> #include <stack> #include <cstring> using namespace std; const int maxn = 150; int main() { #ifdef LOCAL freopen("in", "r", stdin); #endif int n; char data[150]; stack<char> s; scanf("%d", &n); getchar(); while(n--) { fgets(data, maxn, stdin); int len = strlen(data); if(len == 1) { printf("Yes\n"); continue; } len--; while(!s.empty()) s.pop(); for(int i = 0; i < len; i++) { if(!s.empty() && ((data[i] == ')' && s.top() == '(') || (data[i] == ']' && s.top() == '['))) s.pop(); else s.push(data[i]); } if(s.empty()) printf("Yes\n"); else printf("No\n"); } return 0; }
相关文章推荐
- UVA - 673 - Parentheses Balance
- UVA-673 Parentheses Balance
- uva 673 Parentheses Balance 【栈】
- UVa 673 Parentheses Balance
- UVa673 - Parentheses Balance
- UVa - 673 - Parentheses Balance(栈-stack)(Java和C++)
- Uva 673 Parentheses Balance
- UVa-673-Parentheses Balance
- uva673 Parentheses Balance(模拟+栈)
- UVa OJ Parentheses Balance 673 括号平衡
- UVA 673 Parentheses Balance
- UVA 673 Parentheses Balance(括号匹配)
- uva 673 Parentheses Balance
- uva 673 Parentheses Balance
- UVa 673 - Parentheses Balance
- UVA673- Parentheses Balance
- Parentheses Balance UVA - 673
- uva673 Parentheses Balance
- UVA - 673 Parentheses Balance
- UVa 673 - Parentheses Balance