(平衡的括号)Parentheses Balance UVA - 673
2018-02-14 17:48
453 查看
题目链接:Parentheses Balance UVA - 673
思路:栈的应用。。。。错都在回车!!!
代码:
思路:栈的应用。。。。错都在回车!!!
代码:
#include<iostream> #include<string> #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> #include<queue> #include<stack> #include<map> #include<iomanip> #define ll long long using namespace std; const int maxn = 100 + 5; int main() { string s; int t; scanf("%d",&t); getchar(); //吃掉回车。。。。 while(t--) { getline(cin, s); stack<char> c; bool f = true; if(s.length() == 0) { puts("Yes"); continue; } for(int i = 0; i < s.length(); i++) { if(s[i] == '('||s[i] == '[') c.push(s[i]); if(s[i] == ')') { if(c.empty()) { f = false; break;} else if(c.top() == '(') c.pop(); else { f = false; break;} } if(s[i] == ']') { if(c.empty()) { f = false; break;} else if(c.top() == '[') c.pop(); else { f = false; break;} } } if(!c.empty() || !f) puts("No"); else puts("Yes"); } return 0; }
相关文章推荐
- [UVa 673] 平衡的括号(Parentheses Balance)
- Uva 673 Parentheses Balance 平衡的括号
- 平衡的括号(Parentheses Balance,UVa 673)
- UVA673:Parentheses Balance(平衡的括号)
- 平衡的括号(Parentheses Balance, UVa 673)
- uva 673 Parentheses Balance (平衡的括号)堆栈模拟
- 习题6-1 平衡的括号(Parentheses Balance, UVa 673)
- 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
- UVA - 673:Parentheses Balance
- uva-673 Parentheses Balance
- Parentheses Balance UVA - 673
- UVa 673 Parentheses Balance
- Parentheses Balance UVA - 673
- UVa 673 - Parentheses Balance
- UVA 673 - Parentheses Balance