UVa673 - Parentheses Balance
2017-04-03 09:39
323 查看
//UVa673 - Parentheses Balance //已AC #include<iostream> #include<string> #include<stack> using namespace std; int main(){ int T; cin>>T; getchar(); //cin.get(); 读取整数后面的第一个换行符,防止误导后面的getline(); while(T--){ string str; stack<char>s; getline(cin,str); //读取包括换行符在内的一整行(但是不输出换行符??) int ok = 1; for(int i = 0; i < str.size(); i++){ if(str[i] == '(' || str[i] == '[') s.push(str[i]); else if(!s.empty()&& s.top() == '(' && str[i] == ')') s.pop(); else if(!s.empty()&& s.top() == '[' && str[i] == ']') s.pop(); else ok = 0; } ok&&s.empty()? cout<<"Yes\n": cout<<"No\n"; } return 0; }
相关文章推荐
- 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
- UVa 673 Parentheses Balance(栈的使用)
- UVA673 - 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 (栈)
- uva 673 Parentheses Balance(栈)
- UVA - 673 Parentheses Balance
- UVa-673-Parentheses Balance
- UVA - 673 - Parentheses Balance
- 【UVa 673】Parentheses Balance