UVA - 673 Parentheses Balance
2014-09-27 10:55
141 查看
题目大意:给出一系列字符串,求括号是否匹配正确
解题思路:用c++的模板的stack做
看来修改系统还是有bug的,少了else的那个既然还能成功
解题思路:用c++的模板的stack做
看来修改系统还是有bug的,少了else的那个既然还能成功
#include<cstdio> #include<cstring> #include<stack> #include<cstdio> using namespace std; int main() { char str[200]; int test; scanf("%d", &test); getchar(); for(int i = 0; i < test; i++) { stack<char> q; gets(str); int len = strlen(str); int j; for(j = 0 ; j < len; j++) { if(str[j] == '(' || str[j] == '[') q.push(str[j]); if(str[j] == ')') if(q.empty()) break; else if(q.top() == '(') q.pop(); // else // break; if(str[j] == ']' ) if(q.empty()) break; else if(q.top() == '[') q.pop(); // else // break; } if(j != len) printf("No\n"); else if(q.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
- uva 673 Parentheses Balance(栈)
- UVa-673-Parentheses Balance
- UVA - 673 - Parentheses Balance
- 平衡的括号(Parentheses Balance, UVa 673)
- UVA 673 Parentheses Balance (栈)
- UVA673 Parentheses Balance【堆栈+输入流】
- (平衡的括号)Parentheses Balance UVA - 673
- uva 673 - Parentheses Balance
- 习题6-1 平衡的括号(Parentheses Balance, UVa 673)
- UVa 673 Parentheses Balance
- UVA - 673 Parentheses Balance
- UVA - 673 Parentheses Balance
- [UVa 673] 平衡的括号(Parentheses Balance)
- uva 673 - Parentheses Balance
- uva 673 Parentheses Balance
- UVA 673 Parentheses Balance