您的位置:首页 > 其它

Parentheses Balance UVA - 673

2017-05-09 14:09 411 查看
问题类型:stack,极简主义代码~

问题链接

03pie’s solution for [UVA-673]:

#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
cin>>n;getchar();//得到n值,且吃掉回车
while(n--){
stack<char> s;
char x;
while((x=getchar())!='\n'&&x!=EOF){//过滤回车
if(!s.empty()&&x!=' '){ //过滤空格
if(x==')'&&s.top()=='('||x==']'&&s.top()=='[')  s.pop();
else s.push(x);
}
else if(x!=' ') s.push(x);
}
if(s.empty())   cout<<"Yes\n";
else    cout<<"No\n";
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: